[serializer] do not cache resource data pointer for native source.
The cached resource data pointer is a source of non-determinism when creating the snapshot. Long-term we may not keep the native source in memory anyways, so caching the resource data pointer will not be possible. R=ulan@chromium.org BUG=v8:4886 LOG=N Review-Url: https://codereview.chromium.org/1990183002 Cr-Commit-Position: refs/heads/master@{#36361}
This commit is contained in:
parent
f241a61a34
commit
28df32d908
@ -36,12 +36,10 @@ Handle<String> Bootstrapper::SourceLookup(int index) {
|
||||
Vector<const char> source = Source::GetScriptSource(index);
|
||||
NativesExternalStringResource* resource =
|
||||
new NativesExternalStringResource(source.start(), source.length());
|
||||
// We do not expect this to throw an exception. Change this if it does.
|
||||
Handle<String> source_code = isolate_->factory()
|
||||
->NewExternalStringFromOneByte(resource)
|
||||
.ToHandleChecked();
|
||||
Handle<ExternalOneByteString> source_code =
|
||||
isolate_->factory()->NewNativeSourceString(resource);
|
||||
// Mark this external string with a special map.
|
||||
source_code->set_map(isolate_->heap()->native_source_string_map());
|
||||
DCHECK(source_code->is_short());
|
||||
Source::GetSourceCache(heap)->set(index, *source_code);
|
||||
}
|
||||
Handle<Object> cached_source(Source::GetSourceCache(heap)->get(index),
|
||||
|
@ -704,6 +704,21 @@ MaybeHandle<String> Factory::NewExternalStringFromTwoByte(
|
||||
return external_string;
|
||||
}
|
||||
|
||||
Handle<ExternalOneByteString> Factory::NewNativeSourceString(
|
||||
const ExternalOneByteString::Resource* resource) {
|
||||
size_t length = resource->length();
|
||||
DCHECK_LE(length, static_cast<size_t>(String::kMaxLength));
|
||||
|
||||
Handle<Map> map = native_source_string_map();
|
||||
Handle<ExternalOneByteString> external_string =
|
||||
New<ExternalOneByteString>(map, OLD_SPACE);
|
||||
external_string->set_length(static_cast<int>(length));
|
||||
external_string->set_hash_field(String::kEmptyHashField);
|
||||
external_string->set_resource(resource);
|
||||
|
||||
return external_string;
|
||||
}
|
||||
|
||||
|
||||
Handle<Symbol> Factory::NewSymbol() {
|
||||
CALL_HEAP_FUNCTION(
|
||||
|
@ -224,6 +224,10 @@ class Factory final {
|
||||
const ExternalOneByteString::Resource* resource);
|
||||
MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
|
||||
const ExternalTwoByteString::Resource* resource);
|
||||
// Create a new external string object for one-byte encoded native script.
|
||||
// It does not cache the resource data pointer.
|
||||
Handle<ExternalOneByteString> NewNativeSourceString(
|
||||
const ExternalOneByteString::Resource* resource);
|
||||
|
||||
// Create a symbol.
|
||||
Handle<Symbol> NewSymbol();
|
||||
|
@ -2306,8 +2306,9 @@ bool Heap::CreateInitialMaps() {
|
||||
}
|
||||
|
||||
{ // Create a separate external one byte string map for native sources.
|
||||
AllocationResult allocation = AllocateMap(EXTERNAL_ONE_BYTE_STRING_TYPE,
|
||||
ExternalOneByteString::kSize);
|
||||
AllocationResult allocation =
|
||||
AllocateMap(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE,
|
||||
ExternalOneByteString::kShortSize);
|
||||
if (!allocation.To(&obj)) return false;
|
||||
Map* map = Map::cast(obj);
|
||||
map->SetConstructorFunctionIndex(Context::STRING_FUNCTION_INDEX);
|
||||
|
@ -101,10 +101,6 @@ void Deserializer::Deserialize(Isolate* isolate) {
|
||||
isolate_->heap()->undefined_value());
|
||||
}
|
||||
|
||||
// Update data pointers to the external strings containing natives sources.
|
||||
Natives::UpdateSourceCache(isolate_->heap());
|
||||
ExtraNatives::UpdateSourceCache(isolate_->heap());
|
||||
|
||||
// Issue code events for newly deserialized code objects.
|
||||
LOG_CODE_EVENT(isolate_, LogCodeObjects());
|
||||
LOG_CODE_EVENT(isolate_, LogBytecodeHandlers());
|
||||
|
@ -34,24 +34,5 @@ FixedArray* NativesCollection<EXPERIMENTAL_EXTRAS>::GetSourceCache(Heap* heap) {
|
||||
return heap->experimental_extra_natives_source_cache();
|
||||
}
|
||||
|
||||
|
||||
template <NativeType type>
|
||||
void NativesCollection<type>::UpdateSourceCache(Heap* heap) {
|
||||
for (int i = 0; i < GetBuiltinsCount(); i++) {
|
||||
Object* source = GetSourceCache(heap)->get(i);
|
||||
if (!source->IsUndefined()) {
|
||||
ExternalOneByteString::cast(source)->update_data_cache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Explicit template instantiations.
|
||||
template void NativesCollection<CORE>::UpdateSourceCache(Heap* heap);
|
||||
template void NativesCollection<EXPERIMENTAL>::UpdateSourceCache(Heap* heap);
|
||||
template void NativesCollection<EXTRAS>::UpdateSourceCache(Heap* heap);
|
||||
template void NativesCollection<EXPERIMENTAL_EXTRAS>::UpdateSourceCache(
|
||||
Heap* heap);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -44,7 +44,6 @@ class NativesCollection {
|
||||
// The following methods are implemented in natives-common.cc:
|
||||
|
||||
static FixedArray* GetSourceCache(Heap* heap);
|
||||
static void UpdateSourceCache(Heap* heap);
|
||||
};
|
||||
|
||||
typedef NativesCollection<CORE> Natives;
|
||||
|
@ -687,6 +687,9 @@ bool Serializer::ObjectSerializer::SerializeExternalNativeSourceString(
|
||||
|
||||
void Serializer::ObjectSerializer::VisitExternalOneByteString(
|
||||
v8::String::ExternalOneByteStringResource** resource_pointer) {
|
||||
DCHECK_EQ(serializer_->isolate()->heap()->native_source_string_map(),
|
||||
object_->map());
|
||||
DCHECK(ExternalOneByteString::cast(object_)->is_short());
|
||||
Address references_start = reinterpret_cast<Address>(resource_pointer);
|
||||
OutputRawData(references_start);
|
||||
if (SerializeExternalNativeSourceString(
|
||||
|
Loading…
Reference in New Issue
Block a user