Commit 46d34252 authored by domenic's avatar domenic Committed by Commit bot

Put V8 extras into the snapshot

Previously, all extras were "experimental" and left out of the snapshot. This
patch moves them to the snapshot, so now all extras are non-experimental. A
future patch will re-introduce experimental extras as part of the linked bug.

R=yangguo@chromium.org
BUG=https://code.google.com/p/chromium/issues/detail?id=507137
LOG=Y

Review URL: https://codereview.chromium.org/1289603002

Cr-Commit-Position: refs/heads/master@{#30183}
parent 5d0e3b8b
......@@ -384,13 +384,6 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
}
}
if (!context.IsEmpty()) {
// Make sure all builtin scripts are cached.
{
HandleScope scope(isolate);
for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
internal_isolate->bootstrapper()->SourceLookup<i::Natives>(i);
}
}
// If we don't do this then we end up with a stray root pointing at the
// context even after we have disposed of the context.
internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot");
......
......@@ -25,40 +25,11 @@ Bootstrapper::Bootstrapper(Isolate* isolate)
nesting_(0),
extensions_cache_(Script::TYPE_EXTENSION) {}
template <class Source>
inline FixedArray* GetCache(Heap* heap);
template <>
FixedArray* GetCache<Natives>(Heap* heap) {
return heap->natives_source_cache();
}
template <>
FixedArray* GetCache<ExperimentalNatives>(Heap* heap) {
return heap->experimental_natives_source_cache();
}
template <>
FixedArray* GetCache<ExtraNatives>(Heap* heap) {
return heap->extra_natives_source_cache();
}
template <>
FixedArray* GetCache<CodeStubNatives>(Heap* heap) {
return heap->code_stub_natives_source_cache();
}
template <class Source>
Handle<String> Bootstrapper::SourceLookup(int index) {
DCHECK(0 <= index && index < Source::GetBuiltinsCount());
Heap* heap = isolate_->heap();
if (GetCache<Source>(heap)->get(index)->IsUndefined()) {
if (Source::GetSourceCache(heap)->get(index)->IsUndefined()) {
// We can use external strings for the natives.
Vector<const char> source = Source::GetScriptSource(index);
NativesExternalStringResource* resource =
......@@ -69,9 +40,10 @@ Handle<String> Bootstrapper::SourceLookup(int index) {
.ToHandleChecked();
// Mark this external string with a special map.
source_code->set_map(isolate_->heap()->native_source_string_map());
GetCache<Source>(heap)->set(index, *source_code);
Source::GetSourceCache(heap)->set(index, *source_code);
}
Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_);
Handle<Object> cached_source(Source::GetSourceCache(heap)->get(index),
isolate_);
return Handle<String>::cast(cached_source);
}
......@@ -146,10 +118,10 @@ void DeleteNativeSources(Object* maybe_array) {
void Bootstrapper::TearDown() {
DeleteNativeSources(isolate_->heap()->natives_source_cache());
DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache());
DeleteNativeSources(isolate_->heap()->extra_natives_source_cache());
DeleteNativeSources(isolate_->heap()->code_stub_natives_source_cache());
DeleteNativeSources(Natives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(CodeStubNatives::GetSourceCache(isolate_->heap()));
extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
}
......@@ -2115,12 +2087,6 @@ bool Genesis::InstallNatives(ContextType context_type) {
"utils container for native scripts");
native_context()->set_natives_utils_object(*utils);
Handle<JSObject> extras_binding =
factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(extras_binding, CLEAR_INOBJECT_PROPERTIES, 2,
"container for binding to/from extra natives");
native_context()->set_extras_binding_object(*extras_binding);
if (FLAG_expose_natives_as != NULL) {
Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils");
JSObject::AddProperty(builtins, utils_key, utils, NONE);
......@@ -2626,6 +2592,14 @@ bool Genesis::InstallExperimentalNatives() {
bool Genesis::InstallExtraNatives() {
HandleScope scope(isolate());
Handle<JSObject> extras_binding =
factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(extras_binding, CLEAR_INOBJECT_PROPERTIES, 2,
"container for binding to/from extra natives");
native_context()->set_extras_binding_object(*extras_binding);
for (int i = ExtraNatives::GetDebuggerCount();
i < ExtraNatives::GetBuiltinsCount(); i++) {
if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false;
......@@ -3234,19 +3208,19 @@ Genesis::Genesis(Isolate* isolate,
MakeFunctionInstancePrototypeWritable();
if (context_type != THIN_CONTEXT) {
if (!InstallExtraNatives()) return;
if (!ConfigureGlobalObjects(global_proxy_template)) return;
}
isolate->counters()->contexts_created_from_scratch()->Increment();
}
// Install experimental and extra natives. Do not include them into the
// Install experimental natives. Do not include them into the
// snapshot as we should be able to turn them off at runtime. Re-installing
// them after they have already been deserialized would also fail.
if (context_type == FULL_CONTEXT) {
if (!isolate->serializer_enabled()) {
InitializeExperimentalGlobal();
if (!InstallExperimentalNatives()) return;
if (!InstallExtraNatives()) return;
// By now the utils object is useless and can be removed.
native_context()->set_natives_utils_object(
isolate->heap()->undefined_value());
......
......@@ -5,6 +5,10 @@
#ifndef V8_SNAPSHOT_NATIVES_H_
#define V8_SNAPSHOT_NATIVES_H_
#include "src/heap/heap.h"
#include "src/heap/heap-inl.h"
#include "src/objects.h"
#include "src/objects-inl.h"
#include "src/vector.h"
namespace v8 { class StartupData; } // Forward declaration.
......@@ -17,6 +21,8 @@ enum NativeType { CORE, CODE_STUB, EXPERIMENTAL, EXTRAS, D8, TEST };
template <NativeType type>
class NativesCollection {
public:
// The following methods are implemented in js2c-generated code:
// Number of built-in scripts.
static int GetBuiltinsCount();
// Number of debugger implementation scripts.
......@@ -30,6 +36,11 @@ class NativesCollection {
static Vector<const char> GetScriptSource(int index);
static Vector<const char> GetScriptName(int index);
static Vector<const char> GetScriptsSource();
// The following methods are implemented below:
inline static FixedArray* GetSourceCache(Heap* heap);
static void UpdateSourceCache(Heap* heap);
};
typedef NativesCollection<CORE> Natives;
......@@ -37,6 +48,41 @@ typedef NativesCollection<CODE_STUB> CodeStubNatives;
typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives;
typedef NativesCollection<EXTRAS> ExtraNatives;
template <>
inline FixedArray* Natives::GetSourceCache(Heap* heap) {
return heap->natives_source_cache();
}
template <>
inline FixedArray* ExperimentalNatives::GetSourceCache(Heap* heap) {
return heap->experimental_natives_source_cache();
}
template <>
inline FixedArray* ExtraNatives::GetSourceCache(Heap* heap) {
return heap->extra_natives_source_cache();
}
template <>
inline FixedArray* CodeStubNatives::GetSourceCache(Heap* heap) {
return heap->code_stub_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();
}
}
}
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
// Used for reading the natives at runtime. Implementation in natives-empty.cc
void SetNativesFromFile(StartupData* natives_blob);
......
......@@ -570,19 +570,9 @@ void Deserializer::Deserialize(Isolate* isolate) {
}
// Update data pointers to the external strings containing natives sources.
for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
Object* source = isolate_->heap()->natives_source_cache()->get(i);
if (!source->IsUndefined()) {
ExternalOneByteString::cast(source)->update_data_cache();
}
}
for (int i = 0; i < CodeStubNatives::GetBuiltinsCount(); i++) {
Object* source = isolate_->heap()->code_stub_natives_source_cache()->get(i);
if (!source->IsUndefined()) {
ExternalOneByteString::cast(source)->update_data_cache();
}
}
Natives::UpdateSourceCache(isolate_->heap());
ExtraNatives::UpdateSourceCache(isolate_->heap());
CodeStubNatives::UpdateSourceCache(isolate_->heap());
FlushICacheForNewCodeObjects();
......@@ -1181,6 +1171,11 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,
current);
break;
case kExtraNativesStringResource:
current = CopyInNativesSource(
ExtraNatives::GetScriptSource(source_.Get()), current);
break;
case kCodeStubNativesStringResource:
current = CopyInNativesSource(
CodeStubNatives::GetScriptSource(source_.Get()), current);
......@@ -2159,13 +2154,19 @@ void Serializer::ObjectSerializer::VisitExternalOneByteString(
OutputRawData(references_start);
if (SerializeExternalNativeSourceString(
Natives::GetBuiltinsCount(), resource_pointer,
serializer_->isolate()->heap()->natives_source_cache(),
Natives::GetSourceCache(serializer_->isolate()->heap()),
kNativesStringResource)) {
return;
}
if (SerializeExternalNativeSourceString(
ExtraNatives::GetBuiltinsCount(), resource_pointer,
ExtraNatives::GetSourceCache(serializer_->isolate()->heap()),
kExtraNativesStringResource)) {
return;
}
if (SerializeExternalNativeSourceString(
CodeStubNatives::GetBuiltinsCount(), resource_pointer,
serializer_->isolate()->heap()->code_stub_natives_source_cache(),
CodeStubNatives::GetSourceCache(serializer_->isolate()->heap()),
kCodeStubNativesStringResource)) {
return;
}
......
......@@ -383,26 +383,29 @@ class SerializerDeserializer: public ObjectVisitor {
static const int kNextChunk = 0x3e;
// Deferring object content.
static const int kDeferred = 0x3f;
// Used for the source code of the natives, which is in the executable, but
// is referred to from external strings in the snapshot.
static const int kNativesStringResource = 0x5d;
// Used for the source code for compiled stubs, which is in the executable,
// but is referred to from external strings in the snapshot.
static const int kCodeStubNativesStringResource = 0x5e;
// Used for the source code for V8 extras, which is in the executable,
// but is referred to from external strings in the snapshot.
static const int kExtraNativesStringResource = 0x5f;
// A tag emitted at strategic points in the snapshot to delineate sections.
// If the deserializer does not find these at the expected moments then it
// is an indication that the snapshot and the VM do not fit together.
// Examine the build process for architecture, version or configuration
// mismatches.
static const int kSynchronize = 0x17;
// Used for the source code of the natives, which is in the executable, but
// is referred to from external strings in the snapshot.
static const int kNativesStringResource = 0x37;
// Repeats of variable length.
static const int kVariableRepeat = 0x37;
// Raw data of variable length.
static const int kVariableRawData = 0x57;
// Repeats of variable length.
static const int kVariableRepeat = 0x77;
// Alignment prefixes 0x7d..0x7f
static const int kAlignmentPrefix = 0x7d;
// Used for the source code for compiled stubs, which is in the executable,
// but is referred to from external strings in the snapshot.
static const int kCodeStubNativesStringResource = 0x5d;
// 0x5e..0x5f unused
// 0x77 unused
// ---------- byte code range 0x80..0xff ----------
// First 32 root array items.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment