Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/bootstrapper.cc

Issue 1289603002: Put V8 extras into the snapshot (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix comment Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/utils/random-number-generator.h" 9 #include "src/base/utils/random-number-generator.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
11 #include "src/extensions/externalize-string-extension.h" 11 #include "src/extensions/externalize-string-extension.h"
12 #include "src/extensions/free-buffer-extension.h" 12 #include "src/extensions/free-buffer-extension.h"
13 #include "src/extensions/gc-extension.h" 13 #include "src/extensions/gc-extension.h"
14 #include "src/extensions/statistics-extension.h" 14 #include "src/extensions/statistics-extension.h"
15 #include "src/extensions/trigger-failure-extension.h" 15 #include "src/extensions/trigger-failure-extension.h"
16 #include "src/snapshot/natives.h" 16 #include "src/snapshot/natives.h"
17 #include "src/snapshot/snapshot.h" 17 #include "src/snapshot/snapshot.h"
18 #include "third_party/fdlibm/fdlibm.h" 18 #include "third_party/fdlibm/fdlibm.h"
19 19
20 namespace v8 { 20 namespace v8 {
21 namespace internal { 21 namespace internal {
22 22
23 Bootstrapper::Bootstrapper(Isolate* isolate) 23 Bootstrapper::Bootstrapper(Isolate* isolate)
24 : isolate_(isolate), 24 : isolate_(isolate),
25 nesting_(0), 25 nesting_(0),
26 extensions_cache_(Script::TYPE_EXTENSION) {} 26 extensions_cache_(Script::TYPE_EXTENSION) {}
27 27
28
29 template <class Source>
30 inline FixedArray* GetCache(Heap* heap);
31
32
33 template <>
34 FixedArray* GetCache<Natives>(Heap* heap) {
35 return heap->natives_source_cache();
36 }
37
38
39 template <>
40 FixedArray* GetCache<ExperimentalNatives>(Heap* heap) {
41 return heap->experimental_natives_source_cache();
42 }
43
44
45 template <>
46 FixedArray* GetCache<ExtraNatives>(Heap* heap) {
47 return heap->extra_natives_source_cache();
48 }
49
50
51 template <>
52 FixedArray* GetCache<CodeStubNatives>(Heap* heap) {
53 return heap->code_stub_natives_source_cache();
54 }
55
56
57 template <class Source> 28 template <class Source>
58 Handle<String> Bootstrapper::SourceLookup(int index) { 29 Handle<String> Bootstrapper::SourceLookup(int index) {
59 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); 30 DCHECK(0 <= index && index < Source::GetBuiltinsCount());
60 Heap* heap = isolate_->heap(); 31 Heap* heap = isolate_->heap();
61 if (GetCache<Source>(heap)->get(index)->IsUndefined()) { 32 if (Source::GetSourceCache(heap)->get(index)->IsUndefined()) {
62 // We can use external strings for the natives. 33 // We can use external strings for the natives.
63 Vector<const char> source = Source::GetScriptSource(index); 34 Vector<const char> source = Source::GetScriptSource(index);
64 NativesExternalStringResource* resource = 35 NativesExternalStringResource* resource =
65 new NativesExternalStringResource(source.start(), source.length()); 36 new NativesExternalStringResource(source.start(), source.length());
66 // We do not expect this to throw an exception. Change this if it does. 37 // We do not expect this to throw an exception. Change this if it does.
67 Handle<String> source_code = isolate_->factory() 38 Handle<String> source_code = isolate_->factory()
68 ->NewExternalStringFromOneByte(resource) 39 ->NewExternalStringFromOneByte(resource)
69 .ToHandleChecked(); 40 .ToHandleChecked();
70 // Mark this external string with a special map. 41 // Mark this external string with a special map.
71 source_code->set_map(isolate_->heap()->native_source_string_map()); 42 source_code->set_map(isolate_->heap()->native_source_string_map());
72 GetCache<Source>(heap)->set(index, *source_code); 43 Source::GetSourceCache(heap)->set(index, *source_code);
73 } 44 }
74 Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_); 45 Handle<Object> cached_source(Source::GetSourceCache(heap)->get(index),
46 isolate_);
75 return Handle<String>::cast(cached_source); 47 return Handle<String>::cast(cached_source);
76 } 48 }
77 49
78 50
79 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); 51 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index);
80 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( 52 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>(
81 int index); 53 int index);
82 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); 54 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index);
83 template Handle<String> Bootstrapper::SourceLookup<CodeStubNatives>(int index); 55 template Handle<String> Bootstrapper::SourceLookup<CodeStubNatives>(int index);
84 56
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 reinterpret_cast<const NativesExternalStringResource*>( 111 reinterpret_cast<const NativesExternalStringResource*>(
140 ExternalOneByteString::cast(natives_source)->resource()); 112 ExternalOneByteString::cast(natives_source)->resource());
141 delete resource; 113 delete resource;
142 } 114 }
143 } 115 }
144 } 116 }
145 } 117 }
146 118
147 119
148 void Bootstrapper::TearDown() { 120 void Bootstrapper::TearDown() {
149 DeleteNativeSources(isolate_->heap()->natives_source_cache()); 121 DeleteNativeSources(Natives::GetSourceCache(isolate_->heap()));
150 DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache()); 122 DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap()));
151 DeleteNativeSources(isolate_->heap()->extra_natives_source_cache()); 123 DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap()));
152 DeleteNativeSources(isolate_->heap()->code_stub_natives_source_cache()); 124 DeleteNativeSources(CodeStubNatives::GetSourceCache(isolate_->heap()));
153 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical 125 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
154 } 126 }
155 127
156 128
157 class Genesis BASE_EMBEDDED { 129 class Genesis BASE_EMBEDDED {
158 public: 130 public:
159 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, 131 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
160 v8::Local<v8::ObjectTemplate> global_proxy_template, 132 v8::Local<v8::ObjectTemplate> global_proxy_template,
161 v8::ExtensionConfiguration* extensions, ContextType context_type); 133 v8::ExtensionConfiguration* extensions, ContextType context_type);
162 ~Genesis() { } 134 ~Genesis() { }
(...skipping 1930 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 if (!InstallJSBuiltins(builtins)) return false; 2065 if (!InstallJSBuiltins(builtins)) return false;
2094 return true; 2066 return true;
2095 } 2067 }
2096 2068
2097 // Set up the utils object as shared container between native scripts. 2069 // Set up the utils object as shared container between native scripts.
2098 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); 2070 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
2099 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, 2071 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
2100 "utils container for native scripts"); 2072 "utils container for native scripts");
2101 native_context()->set_natives_utils_object(*utils); 2073 native_context()->set_natives_utils_object(*utils);
2102 2074
2103 Handle<JSObject> extras_binding =
2104 factory()->NewJSObject(isolate()->object_function());
2105 JSObject::NormalizeProperties(extras_binding, CLEAR_INOBJECT_PROPERTIES, 2,
2106 "container for binding to/from extra natives");
2107 native_context()->set_extras_binding_object(*extras_binding);
2108
2109 if (FLAG_expose_natives_as != NULL) { 2075 if (FLAG_expose_natives_as != NULL) {
2110 Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils"); 2076 Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils");
2111 JSObject::AddProperty(builtins, utils_key, utils, NONE); 2077 JSObject::AddProperty(builtins, utils_key, utils, NONE);
2112 } 2078 }
2113 2079
2114 { // -- S c r i p t 2080 { // -- S c r i p t
2115 // Builtin functions for Script. 2081 // Builtin functions for Script.
2116 Handle<JSFunction> script_fun = InstallFunction( 2082 Handle<JSFunction> script_fun = InstallFunction(
2117 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, 2083 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
2118 isolate()->initial_object_prototype(), Builtins::kIllegal); 2084 isolate()->initial_object_prototype(), Builtins::kIllegal);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
2607 2573
2608 if (!CallUtilsFunction(isolate(), "PostExperimentals")) return false; 2574 if (!CallUtilsFunction(isolate(), "PostExperimentals")) return false;
2609 2575
2610 InstallExperimentalNativeFunctions(); 2576 InstallExperimentalNativeFunctions();
2611 InstallExperimentalBuiltinFunctionIds(); 2577 InstallExperimentalBuiltinFunctionIds();
2612 return true; 2578 return true;
2613 } 2579 }
2614 2580
2615 2581
2616 bool Genesis::InstallExtraNatives() { 2582 bool Genesis::InstallExtraNatives() {
2583 HandleScope scope(isolate());
2584
2585 Handle<JSObject> extras_binding =
2586 factory()->NewJSObject(isolate()->object_function());
2587 JSObject::NormalizeProperties(extras_binding, CLEAR_INOBJECT_PROPERTIES, 2,
2588 "container for binding to/from extra natives");
2589 native_context()->set_extras_binding_object(*extras_binding);
2590
2617 for (int i = ExtraNatives::GetDebuggerCount(); 2591 for (int i = ExtraNatives::GetDebuggerCount();
2618 i < ExtraNatives::GetBuiltinsCount(); i++) { 2592 i < ExtraNatives::GetBuiltinsCount(); i++) {
2619 if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false; 2593 if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false;
2620 } 2594 }
2621 2595
2622 return true; 2596 return true;
2623 } 2597 }
2624 2598
2625 2599
2626 bool Genesis::InstallDebuggerNatives() { 2600 bool Genesis::InstallDebuggerNatives() {
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 CreateNewGlobals(global_proxy_template, global_proxy); 3189 CreateNewGlobals(global_proxy_template, global_proxy);
3216 HookUpGlobalProxy(global_object, global_proxy); 3190 HookUpGlobalProxy(global_object, global_proxy);
3217 InitializeGlobal(global_object, empty_function, context_type); 3191 InitializeGlobal(global_object, empty_function, context_type);
3218 InitializeNormalizedMapCaches(); 3192 InitializeNormalizedMapCaches();
3219 3193
3220 if (!InstallNatives(context_type)) return; 3194 if (!InstallNatives(context_type)) return;
3221 3195
3222 MakeFunctionInstancePrototypeWritable(); 3196 MakeFunctionInstancePrototypeWritable();
3223 3197
3224 if (context_type != THIN_CONTEXT) { 3198 if (context_type != THIN_CONTEXT) {
3199 if (!InstallExtraNatives()) return;
3225 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3200 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3226 } 3201 }
3227 isolate->counters()->contexts_created_from_scratch()->Increment(); 3202 isolate->counters()->contexts_created_from_scratch()->Increment();
3228 } 3203 }
3229 3204
3230 // Install experimental and extra natives. Do not include them into the 3205 // Install experimental natives. Do not include them into the
3231 // snapshot as we should be able to turn them off at runtime. Re-installing 3206 // snapshot as we should be able to turn them off at runtime. Re-installing
3232 // them after they have already been deserialized would also fail. 3207 // them after they have already been deserialized would also fail.
3233 if (context_type == FULL_CONTEXT) { 3208 if (context_type == FULL_CONTEXT) {
3234 if (!isolate->serializer_enabled()) { 3209 if (!isolate->serializer_enabled()) {
3235 InitializeExperimentalGlobal(); 3210 InitializeExperimentalGlobal();
3236 if (!InstallExperimentalNatives()) return; 3211 if (!InstallExperimentalNatives()) return;
3237 if (!InstallExtraNatives()) return;
3238 // By now the utils object is useless and can be removed. 3212 // By now the utils object is useless and can be removed.
3239 native_context()->set_natives_utils_object( 3213 native_context()->set_natives_utils_object(
3240 isolate->heap()->undefined_value()); 3214 isolate->heap()->undefined_value());
3241 } 3215 }
3242 3216
3243 // The serializer cannot serialize typed arrays. Reset those typed arrays 3217 // The serializer cannot serialize typed arrays. Reset those typed arrays
3244 // for each new context. 3218 // for each new context.
3245 InitializeBuiltinTypedArrays(); 3219 InitializeBuiltinTypedArrays();
3246 } else if (context_type == DEBUG_CONTEXT) { 3220 } else if (context_type == DEBUG_CONTEXT) {
3247 DCHECK(!isolate->serializer_enabled()); 3221 DCHECK(!isolate->serializer_enabled());
(...skipping 28 matching lines...) Expand all
3276 } 3250 }
3277 3251
3278 3252
3279 // Called when the top-level V8 mutex is destroyed. 3253 // Called when the top-level V8 mutex is destroyed.
3280 void Bootstrapper::FreeThreadResources() { 3254 void Bootstrapper::FreeThreadResources() {
3281 DCHECK(!IsActive()); 3255 DCHECK(!IsActive());
3282 } 3256 }
3283 3257
3284 } // namespace internal 3258 } // namespace internal
3285 } // namespace v8 3259 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/snapshot/natives.h » ('j') | src/snapshot/serialize.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698