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

Side by Side Diff: src/bootstrapper.cc

Issue 1213203007: Create a internal, global native context used only for generated code stubs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review feedback Created 5 years, 5 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
« no previous file with comments | « src/bootstrapper.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 30 matching lines...) Expand all
41 return heap->experimental_natives_source_cache(); 41 return heap->experimental_natives_source_cache();
42 } 42 }
43 43
44 44
45 template <> 45 template <>
46 FixedArray* GetCache<ExtraNatives>(Heap* heap) { 46 FixedArray* GetCache<ExtraNatives>(Heap* heap) {
47 return heap->extra_natives_source_cache(); 47 return heap->extra_natives_source_cache();
48 } 48 }
49 49
50 50
51 template <>
52 FixedArray* GetCache<CodeStubNatives>(Heap* heap) {
53 return heap->code_stub_natives_source_cache();
54 }
55
56
51 template <class Source> 57 template <class Source>
52 Handle<String> Bootstrapper::SourceLookup(int index) { 58 Handle<String> Bootstrapper::SourceLookup(int index) {
53 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); 59 DCHECK(0 <= index && index < Source::GetBuiltinsCount());
54 Heap* heap = isolate_->heap(); 60 Heap* heap = isolate_->heap();
55 if (GetCache<Source>(heap)->get(index)->IsUndefined()) { 61 if (GetCache<Source>(heap)->get(index)->IsUndefined()) {
56 // We can use external strings for the natives. 62 // We can use external strings for the natives.
57 Vector<const char> source = Source::GetScriptSource(index); 63 Vector<const char> source = Source::GetScriptSource(index);
58 NativesExternalStringResource* resource = 64 NativesExternalStringResource* resource =
59 new NativesExternalStringResource(source.start(), source.length()); 65 new NativesExternalStringResource(source.start(), source.length());
60 // We do not expect this to throw an exception. Change this if it does. 66 // We do not expect this to throw an exception. Change this if it does.
61 Handle<String> source_code = isolate_->factory() 67 Handle<String> source_code = isolate_->factory()
62 ->NewExternalStringFromOneByte(resource) 68 ->NewExternalStringFromOneByte(resource)
63 .ToHandleChecked(); 69 .ToHandleChecked();
64 // Mark this external string with a special map. 70 // Mark this external string with a special map.
65 source_code->set_map(isolate_->heap()->native_source_string_map()); 71 source_code->set_map(isolate_->heap()->native_source_string_map());
66 GetCache<Source>(heap)->set(index, *source_code); 72 GetCache<Source>(heap)->set(index, *source_code);
67 } 73 }
68 Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_); 74 Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_);
69 return Handle<String>::cast(cached_source); 75 return Handle<String>::cast(cached_source);
70 } 76 }
71 77
72 78
73 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); 79 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index);
74 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( 80 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>(
75 int index); 81 int index);
76 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); 82 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index);
83 template Handle<String> Bootstrapper::SourceLookup<CodeStubNatives>(int index);
77 84
78 85
79 void Bootstrapper::Initialize(bool create_heap_objects) { 86 void Bootstrapper::Initialize(bool create_heap_objects) {
80 extensions_cache_.Initialize(isolate_, create_heap_objects); 87 extensions_cache_.Initialize(isolate_, create_heap_objects);
81 } 88 }
82 89
83 90
84 static const char* GCFunctionName() { 91 static const char* GCFunctionName() {
85 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; 92 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0;
86 return flag_given ? FLAG_expose_gc_as : "gc"; 93 return flag_given ? FLAG_expose_gc_as : "gc";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 142 }
136 } 143 }
137 } 144 }
138 } 145 }
139 146
140 147
141 void Bootstrapper::TearDown() { 148 void Bootstrapper::TearDown() {
142 DeleteNativeSources(isolate_->heap()->natives_source_cache()); 149 DeleteNativeSources(isolate_->heap()->natives_source_cache());
143 DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache()); 150 DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache());
144 DeleteNativeSources(isolate_->heap()->extra_natives_source_cache()); 151 DeleteNativeSources(isolate_->heap()->extra_natives_source_cache());
152 DeleteNativeSources(isolate_->heap()->code_stub_natives_source_cache());
145 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical 153 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
146 } 154 }
147 155
148 156
149 class Genesis BASE_EMBEDDED { 157 class Genesis BASE_EMBEDDED {
150 public: 158 public:
151 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, 159 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
152 v8::Local<v8::ObjectTemplate> global_proxy_template, 160 v8::Local<v8::ObjectTemplate> global_proxy_template,
153 v8::ExtensionConfiguration* extensions); 161 v8::ExtensionConfiguration* extensions, ContextType context_type);
154 ~Genesis() { } 162 ~Genesis() { }
155 163
156 Isolate* isolate() const { return isolate_; } 164 Isolate* isolate() const { return isolate_; }
157 Factory* factory() const { return isolate_->factory(); } 165 Factory* factory() const { return isolate_->factory(); }
158 Heap* heap() const { return isolate_->heap(); } 166 Heap* heap() const { return isolate_->heap(); }
159 167
160 Handle<Context> result() { return result_; } 168 Handle<Context> result() { return result_; }
161 169
162 private: 170 private:
163 Handle<Context> native_context() { return native_context_; } 171 Handle<Context> native_context() { return native_context_; }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // other objects in the snapshot. 204 // other objects in the snapshot.
197 void HookUpGlobalObject(Handle<GlobalObject> global_object, 205 void HookUpGlobalObject(Handle<GlobalObject> global_object,
198 Handle<FixedArray> outdated_contexts); 206 Handle<FixedArray> outdated_contexts);
199 // The native context has a ScriptContextTable that store declarative bindings 207 // The native context has a ScriptContextTable that store declarative bindings
200 // made in script scopes. Add a "this" binding to that table pointing to the 208 // made in script scopes. Add a "this" binding to that table pointing to the
201 // global proxy. 209 // global proxy.
202 void InstallGlobalThisBinding(); 210 void InstallGlobalThisBinding();
203 void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts); 211 void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts);
204 // New context initialization. Used for creating a context from scratch. 212 // New context initialization. Used for creating a context from scratch.
205 void InitializeGlobal(Handle<GlobalObject> global_object, 213 void InitializeGlobal(Handle<GlobalObject> global_object,
206 Handle<JSFunction> empty_function); 214 Handle<JSFunction> empty_function,
215 ContextType context_type);
207 void InitializeExperimentalGlobal(); 216 void InitializeExperimentalGlobal();
208 // Installs the contents of the native .js files on the global objects. 217 // Installs the contents of the native .js files on the global objects.
209 // Used for creating a context from scratch. 218 // Used for creating a context from scratch.
210 void InstallNativeFunctions(); 219 void InstallNativeFunctions();
211 void InstallExperimentalNativeFunctions(); 220 void InstallExperimentalNativeFunctions();
212 // Typed arrays are not serializable and have to initialized afterwards. 221 // Typed arrays are not serializable and have to initialized afterwards.
213 void InitializeBuiltinTypedArrays(); 222 void InitializeBuiltinTypedArrays();
214 223
215 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ 224 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \
216 void InstallNativeFunctions_##id(); \ 225 void InstallNativeFunctions_##id(); \
217 void InitializeGlobal_##id(); 226 void InitializeGlobal_##id();
218 227
219 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) 228 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
220 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) 229 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
221 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) 230 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
222 #undef DECLARE_FEATURE_INITIALIZATION 231 #undef DECLARE_FEATURE_INITIALIZATION
223 232
224 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, 233 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
225 const char* name, 234 const char* name,
226 ElementsKind elements_kind); 235 ElementsKind elements_kind);
227 bool InstallNatives(); 236 bool InstallNatives(ContextType context_type);
228 237
229 void InstallTypedArray( 238 void InstallTypedArray(
230 const char* name, 239 const char* name,
231 ElementsKind elements_kind, 240 ElementsKind elements_kind,
232 Handle<JSFunction>* fun, 241 Handle<JSFunction>* fun,
233 Handle<Map>* external_map); 242 Handle<Map>* external_map);
234 bool InstallExperimentalNatives(); 243 bool InstallExperimentalNatives();
235 bool InstallExtraNatives(); 244 bool InstallExtraNatives();
236 void InstallBuiltinFunctionIds(); 245 void InstallBuiltinFunctionIds();
237 void InstallExperimentalBuiltinFunctionIds(); 246 void InstallExperimentalBuiltinFunctionIds();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 352
344 void Bootstrapper::Iterate(ObjectVisitor* v) { 353 void Bootstrapper::Iterate(ObjectVisitor* v) {
345 extensions_cache_.Iterate(v); 354 extensions_cache_.Iterate(v);
346 v->Synchronize(VisitorSynchronization::kExtensions); 355 v->Synchronize(VisitorSynchronization::kExtensions);
347 } 356 }
348 357
349 358
350 Handle<Context> Bootstrapper::CreateEnvironment( 359 Handle<Context> Bootstrapper::CreateEnvironment(
351 MaybeHandle<JSGlobalProxy> maybe_global_proxy, 360 MaybeHandle<JSGlobalProxy> maybe_global_proxy,
352 v8::Local<v8::ObjectTemplate> global_proxy_template, 361 v8::Local<v8::ObjectTemplate> global_proxy_template,
353 v8::ExtensionConfiguration* extensions) { 362 v8::ExtensionConfiguration* extensions, ContextType context_type) {
354 HandleScope scope(isolate_); 363 HandleScope scope(isolate_);
355 Genesis genesis( 364 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template,
356 isolate_, maybe_global_proxy, global_proxy_template, extensions); 365 extensions, context_type);
357 Handle<Context> env = genesis.result(); 366 Handle<Context> env = genesis.result();
358 if (env.is_null() || !InstallExtensions(env, extensions)) { 367 if (env.is_null() ||
368 (context_type == FULL_CONTEXT && !InstallExtensions(env, extensions))) {
359 return Handle<Context>(); 369 return Handle<Context>();
360 } 370 }
361 return scope.CloseAndEscape(env); 371 return scope.CloseAndEscape(env);
362 } 372 }
363 373
364 374
375 bool Bootstrapper::CreateCodeStubContext(Isolate* isolate) {
376 HandleScope scope(isolate);
377 SaveContext save_context(isolate);
378 BootstrapperActive active(this);
379
380 v8::ExtensionConfiguration no_extensions;
381 Handle<Context> native_context = CreateEnvironment(
382 MaybeHandle<JSGlobalProxy>(), v8::Local<v8::ObjectTemplate>(),
383 &no_extensions, THIN_CONTEXT);
384 isolate->heap()->set_code_stub_context(*native_context);
385 isolate->set_context(*native_context);
386 Handle<JSObject> code_stub_exports =
387 isolate->factory()->NewJSObject(isolate->object_function());
388 JSObject::NormalizeProperties(code_stub_exports, CLEAR_INOBJECT_PROPERTIES, 2,
389 "container to export to extra natives");
390 isolate->heap()->set_code_stub_exports_object(*code_stub_exports);
391 return InstallCodeStubNatives(isolate);
392 }
393
394
365 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { 395 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
366 // object.__proto__ = proto; 396 // object.__proto__ = proto;
367 Handle<Map> old_map = Handle<Map>(object->map()); 397 Handle<Map> old_map = Handle<Map>(object->map());
368 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); 398 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype");
369 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); 399 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE);
370 JSObject::MigrateToMap(object, new_map); 400 JSObject::MigrateToMap(object, new_map);
371 } 401 }
372 402
373 403
374 void Bootstrapper::DetachGlobal(Handle<Context> env) { 404 void Bootstrapper::DetachGlobal(Handle<Context> env) {
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 // Set up the reference from the global object to the builtins object. 1015 // Set up the reference from the global object to the builtins object.
986 JSGlobalObject::cast(*global_object)->set_builtins(*builtins_global); 1016 JSGlobalObject::cast(*global_object)->set_builtins(*builtins_global);
987 TransferNamedProperties(global_object_from_snapshot, global_object); 1017 TransferNamedProperties(global_object_from_snapshot, global_object);
988 TransferIndexedProperties(global_object_from_snapshot, global_object); 1018 TransferIndexedProperties(global_object_from_snapshot, global_object);
989 } 1019 }
990 1020
991 1021
992 // This is only called if we are not using snapshots. The equivalent 1022 // This is only called if we are not using snapshots. The equivalent
993 // work in the snapshot case is done in HookUpGlobalObject. 1023 // work in the snapshot case is done in HookUpGlobalObject.
994 void Genesis::InitializeGlobal(Handle<GlobalObject> global_object, 1024 void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
995 Handle<JSFunction> empty_function) { 1025 Handle<JSFunction> empty_function,
1026 ContextType context_type) {
996 // --- N a t i v e C o n t e x t --- 1027 // --- N a t i v e C o n t e x t ---
997 // Use the empty function as closure (no scope info). 1028 // Use the empty function as closure (no scope info).
998 native_context()->set_closure(*empty_function); 1029 native_context()->set_closure(*empty_function);
999 native_context()->set_previous(NULL); 1030 native_context()->set_previous(NULL);
1000 // Set extension and global object. 1031 // Set extension and global object.
1001 native_context()->set_extension(*global_object); 1032 native_context()->set_extension(*global_object);
1002 native_context()->set_global_object(*global_object); 1033 native_context()->set_global_object(*global_object);
1003 // Security setup: Set the security token of the native context to the global 1034 // Security setup: Set the security token of the native context to the global
1004 // object. This makes the security check between two different contexts fail 1035 // object. This makes the security check between two different contexts fail
1005 // by default even in case of global object reinitialization. 1036 // by default even in case of global object reinitialization.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, 1241 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
1211 Smi::FromInt(0), 1242 Smi::FromInt(0),
1212 SKIP_WRITE_BARRIER); // It's a Smi. 1243 SKIP_WRITE_BARRIER); // It's a Smi.
1213 proto_map->set_is_prototype_map(true); 1244 proto_map->set_is_prototype_map(true);
1214 Map::SetPrototype(initial_map, proto); 1245 Map::SetPrototype(initial_map, proto);
1215 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), 1246 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
1216 JSRegExp::IRREGEXP, factory->empty_string(), 1247 JSRegExp::IRREGEXP, factory->empty_string(),
1217 JSRegExp::Flags(0), 0); 1248 JSRegExp::Flags(0), 0);
1218 } 1249 }
1219 1250
1251 // Initialize the embedder data slot.
1252 Handle<FixedArray> embedder_data = factory->NewFixedArray(3);
1253 native_context()->set_embedder_data(*embedder_data);
1254
1255 if (context_type == THIN_CONTEXT) return;
1256
1220 { // -- J S O N 1257 { // -- J S O N
1221 Handle<String> name = factory->InternalizeUtf8String("JSON"); 1258 Handle<String> name = factory->InternalizeUtf8String("JSON");
1222 Handle<JSFunction> cons = factory->NewFunction(name); 1259 Handle<JSFunction> cons = factory->NewFunction(name);
1223 JSFunction::SetInstancePrototype(cons, 1260 JSFunction::SetInstancePrototype(cons,
1224 Handle<Object>(native_context()->initial_object_prototype(), isolate)); 1261 Handle<Object>(native_context()->initial_object_prototype(), isolate));
1225 cons->SetInstanceClassName(*name); 1262 cons->SetInstanceClassName(*name);
1226 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); 1263 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED);
1227 DCHECK(json_object->IsJSObject()); 1264 DCHECK(json_object->IsJSObject());
1228 JSObject::AddProperty(global, name, json_object, DONT_ENUM); 1265 JSObject::AddProperty(global, name, json_object, DONT_ENUM);
1229 native_context()->set_json_object(*json_object); 1266 native_context()->set_json_object(*json_object);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 { 1492 {
1456 // Set up the call-as-constructor delegate. 1493 // Set up the call-as-constructor delegate.
1457 Handle<Code> code = 1494 Handle<Code> code =
1458 Handle<Code>(isolate->builtins()->builtin( 1495 Handle<Code>(isolate->builtins()->builtin(
1459 Builtins::kHandleApiCallAsConstructor)); 1496 Builtins::kHandleApiCallAsConstructor));
1460 Handle<JSFunction> delegate = factory->NewFunction( 1497 Handle<JSFunction> delegate = factory->NewFunction(
1461 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); 1498 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize);
1462 native_context()->set_call_as_constructor_delegate(*delegate); 1499 native_context()->set_call_as_constructor_delegate(*delegate);
1463 delegate->shared()->DontAdaptArguments(); 1500 delegate->shared()->DontAdaptArguments();
1464 } 1501 }
1465
1466 // Initialize the embedder data slot.
1467 Handle<FixedArray> embedder_data = factory->NewFixedArray(3);
1468 native_context()->set_embedder_data(*embedder_data);
1469 } 1502 }
1470 1503
1471 1504
1472 void Genesis::InstallTypedArray( 1505 void Genesis::InstallTypedArray(
1473 const char* name, 1506 const char* name,
1474 ElementsKind elements_kind, 1507 ElementsKind elements_kind,
1475 Handle<JSFunction>* fun, 1508 Handle<JSFunction>* fun,
1476 Handle<Map>* external_map) { 1509 Handle<Map>* external_map) {
1477 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); 1510 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
1478 Handle<JSFunction> result = InstallFunction( 1511 Handle<JSFunction> result = InstallFunction(
(...skipping 16 matching lines...) Expand all
1495 void Genesis::InitializeExperimentalGlobal() { 1528 void Genesis::InitializeExperimentalGlobal() {
1496 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); 1529 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
1497 1530
1498 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) 1531 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
1499 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) 1532 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
1500 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) 1533 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
1501 #undef FEATURE_INITIALIZE_GLOBAL 1534 #undef FEATURE_INITIALIZE_GLOBAL
1502 } 1535 }
1503 1536
1504 1537
1505 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { 1538 bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
1506 Vector<const char> name = Natives::GetScriptName(index); 1539 Vector<const char> name = Natives::GetScriptName(index);
1507 Handle<String> source_code = 1540 Handle<String> source_code =
1508 isolate->bootstrapper()->SourceLookup<Natives>(index); 1541 isolate->bootstrapper()->SourceLookup<Natives>(index);
1509 Handle<Object> global = isolate->global_object(); 1542 Handle<Object> global = isolate->global_object();
1510 Handle<Object> utils = isolate->natives_utils_object(); 1543 Handle<Object> utils = isolate->natives_utils_object();
1511 Handle<Object> args[] = {global, utils}; 1544 Handle<Object> args[] = {global, utils};
1512 return CompileNative(isolate, name, source_code, arraysize(args), args); 1545
1546 return Bootstrapper::CompileNative(
1547 isolate, name, Handle<JSObject>(isolate->native_context()->builtins()),
1548 source_code, arraysize(args), args);
1513 } 1549 }
1514 1550
1515 1551
1516 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { 1552 bool Bootstrapper::CompileExperimentalBuiltin(Isolate* isolate, int index) {
1517 HandleScope scope(isolate); 1553 HandleScope scope(isolate);
1518 Vector<const char> name = ExperimentalNatives::GetScriptName(index); 1554 Vector<const char> name = ExperimentalNatives::GetScriptName(index);
1519 Handle<String> source_code = 1555 Handle<String> source_code =
1520 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); 1556 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index);
1521 Handle<Object> global = isolate->global_object(); 1557 Handle<Object> global = isolate->global_object();
1522 Handle<Object> utils = isolate->natives_utils_object(); 1558 Handle<Object> utils = isolate->natives_utils_object();
1523 Handle<Object> args[] = {global, utils}; 1559 Handle<Object> args[] = {global, utils};
1524 return CompileNative(isolate, name, source_code, arraysize(args), args); 1560 return Bootstrapper::CompileNative(
1561 isolate, name, Handle<JSObject>(isolate->native_context()->builtins()),
1562 source_code, arraysize(args), args);
1525 } 1563 }
1526 1564
1527 1565
1528 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) { 1566 bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) {
1529 HandleScope scope(isolate); 1567 HandleScope scope(isolate);
1530 Vector<const char> name = ExtraNatives::GetScriptName(index); 1568 Vector<const char> name = ExtraNatives::GetScriptName(index);
1531 Handle<String> source_code = 1569 Handle<String> source_code =
1532 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); 1570 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index);
1533 Handle<Object> global = isolate->global_object(); 1571 Handle<Object> global = isolate->global_object();
1534 Handle<Object> exports = isolate->extras_exports_object(); 1572 Handle<Object> exports = isolate->extras_exports_object();
1535 Handle<Object> args[] = {global, exports}; 1573 Handle<Object> args[] = {global, exports};
1536 return CompileNative(isolate, name, source_code, arraysize(args), args); 1574 return Bootstrapper::CompileNative(
1575 isolate, name, Handle<JSObject>(isolate->native_context()->builtins()),
1576 source_code, arraysize(args), args);
1537 } 1577 }
1538 1578
1539 1579
1540 bool Genesis::CompileNative(Isolate* isolate, Vector<const char> name, 1580 bool Bootstrapper::CompileCodeStubBuiltin(Isolate* isolate, int index) {
1541 Handle<String> source, int argc, 1581 HandleScope scope(isolate);
1542 Handle<Object> argv[]) { 1582 Vector<const char> name = CodeStubNatives::GetScriptName(index);
1583 Handle<String> source_code =
1584 isolate->bootstrapper()->SourceLookup<CodeStubNatives>(index);
1585 Handle<JSObject> global(isolate->global_object());
1586 Handle<JSObject> exports(isolate->heap()->code_stub_exports_object());
1587 Handle<Object> args[] = {global, exports};
1588 bool result =
1589 CompileNative(isolate, name, global, source_code, arraysize(args), args);
1590 return result;
1591 }
1592
1593
1594 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
1595 Handle<JSObject> receiver,
1596 Handle<String> source, int argc,
1597 Handle<Object> argv[]) {
1543 SuppressDebug compiling_natives(isolate->debug()); 1598 SuppressDebug compiling_natives(isolate->debug());
1544 // During genesis, the boilerplate for stack overflow won't work until the 1599 // During genesis, the boilerplate for stack overflow won't work until the
1545 // environment has been at least partially initialized. Add a stack check 1600 // environment has been at least partially initialized. Add a stack check
1546 // before entering JS code to catch overflow early. 1601 // before entering JS code to catch overflow early.
1547 StackLimitCheck check(isolate); 1602 StackLimitCheck check(isolate);
1548 if (check.JsHasOverflowed(1 * KB)) { 1603 if (check.JsHasOverflowed(1 * KB)) {
1549 isolate->StackOverflow(); 1604 isolate->StackOverflow();
1550 return false; 1605 return false;
1551 } 1606 }
1552 1607
1553 Handle<Context> context(isolate->context()); 1608 Handle<Context> context(isolate->context());
1554 1609
1555 Handle<String> script_name = 1610 Handle<String> script_name =
1556 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); 1611 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
1557 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( 1612 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript(
1558 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), 1613 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
1559 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, 1614 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE,
1560 false); 1615 false);
1561 if (function_info.is_null()) return false; 1616 if (function_info.is_null()) return false;
1562 1617
1563 DCHECK(context->IsNativeContext()); 1618 DCHECK(context->IsNativeContext());
1564 1619
1565 Handle<Context> runtime_context(context->runtime_context()); 1620 Handle<Context> runtime_context(context->runtime_context());
1566 Handle<JSBuiltinsObject> receiver(context->builtins());
1567 Handle<JSFunction> fun = 1621 Handle<JSFunction> fun =
1568 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, 1622 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
1569 runtime_context); 1623 runtime_context);
1570 1624
1571 // For non-extension scripts, run script to get the function wrapper. 1625 // For non-extension scripts, run script to get the function wrapper.
1572 Handle<Object> wrapper; 1626 Handle<Object> wrapper;
1573 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) { 1627 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
1574 return false; 1628 return false;
1575 } 1629 }
1576 // Then run the function wrapper. 1630 // Then run the function wrapper.
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 { // Add length. 2016 { // Add length.
1963 AccessorConstantDescriptor d(Handle<Name>(Name::cast(array_length->name())), 2017 AccessorConstantDescriptor d(Handle<Name>(Name::cast(array_length->name())),
1964 array_length, attribs); 2018 array_length, attribs);
1965 initial_map->AppendDescriptor(&d); 2019 initial_map->AppendDescriptor(&d);
1966 } 2020 }
1967 2021
1968 return array_function; 2022 return array_function;
1969 } 2023 }
1970 2024
1971 2025
1972 bool Genesis::InstallNatives() { 2026 bool Genesis::InstallNatives(ContextType context_type) {
1973 HandleScope scope(isolate()); 2027 HandleScope scope(isolate());
1974 2028
1975 // Create a function for the builtins object. Allocate space for the 2029 // Create a function for the builtins object. Allocate space for the
1976 // JavaScript builtins, a reference to the builtins object 2030 // JavaScript builtins, a reference to the builtins object
1977 // (itself) and a reference to the native_context directly in the object. 2031 // (itself) and a reference to the native_context directly in the object.
1978 Handle<Code> code = Handle<Code>( 2032 Handle<Code> code = Handle<Code>(
1979 isolate()->builtins()->builtin(Builtins::kIllegal)); 2033 isolate()->builtins()->builtin(Builtins::kIllegal));
1980 Handle<JSFunction> builtins_fun = factory()->NewFunction( 2034 Handle<JSFunction> builtins_fun = factory()->NewFunction(
1981 factory()->empty_string(), code, JS_BUILTINS_OBJECT_TYPE, 2035 factory()->empty_string(), code, JS_BUILTINS_OBJECT_TYPE,
1982 JSBuiltinsObject::kSize); 2036 JSBuiltinsObject::kSize);
(...skipping 27 matching lines...) Expand all
2010 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string()); 2064 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string());
2011 DCHECK(bridge->context() == *isolate()->native_context()); 2065 DCHECK(bridge->context() == *isolate()->native_context());
2012 2066
2013 // Allocate the builtins context. 2067 // Allocate the builtins context.
2014 Handle<Context> context = 2068 Handle<Context> context =
2015 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); 2069 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
2016 context->set_global_object(*builtins); // override builtins global object 2070 context->set_global_object(*builtins); // override builtins global object
2017 2071
2018 native_context()->set_runtime_context(*context); 2072 native_context()->set_runtime_context(*context);
2019 2073
2074 if (context_type == THIN_CONTEXT) {
2075 int js_builtins_script_index = Natives::GetDebuggerCount();
2076 if (!Bootstrapper::CompileBuiltin(isolate(), js_builtins_script_index))
2077 return false;
2078 if (!InstallJSBuiltins(builtins)) return false;
2079 return true;
2080 }
2081
2020 // Set up the utils object as shared container between native scripts. 2082 // Set up the utils object as shared container between native scripts.
2021 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); 2083 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
2022 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, 2084 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
2023 "utils container for native scripts"); 2085 "utils container for native scripts");
2024 native_context()->set_natives_utils_object(*utils); 2086 native_context()->set_natives_utils_object(*utils);
2025 2087
2026 Handle<JSObject> extras_exports = 2088 Handle<JSObject> extras_exports =
2027 factory()->NewJSObject(isolate()->object_function()); 2089 factory()->NewJSObject(isolate()->object_function());
2028 JSObject::NormalizeProperties(extras_exports, CLEAR_INOBJECT_PROPERTIES, 2, 2090 JSObject::NormalizeProperties(extras_exports, CLEAR_INOBJECT_PROPERTIES, 2,
2029 "container to export to extra natives"); 2091 "container to export to extra natives");
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 static const PropertyAttributes attributes = 2370 static const PropertyAttributes attributes =
2309 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 2371 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
2310 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \ 2372 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \
2311 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \ 2373 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \
2312 JSObject::AddProperty(builtins, varname, factory()->name(), attributes); 2374 JSObject::AddProperty(builtins, varname, factory()->name(), attributes);
2313 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL) 2375 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL)
2314 #undef INSTALL_PUBLIC_SYMBOL 2376 #undef INSTALL_PUBLIC_SYMBOL
2315 } 2377 }
2316 2378
2317 int i = Natives::GetDebuggerCount(); 2379 int i = Natives::GetDebuggerCount();
2318 if (!CompileBuiltin(isolate(), i)) return false; 2380 if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
2381
2319 if (!InstallJSBuiltins(builtins)) return false; 2382 if (!InstallJSBuiltins(builtins)) return false;
2320 2383
2321 for (++i; i < Natives::GetBuiltinsCount(); ++i) { 2384 for (++i; i < Natives::GetBuiltinsCount(); ++i) {
2322 if (!CompileBuiltin(isolate(), i)) return false; 2385 if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
2323 } 2386 }
2324 2387
2325 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; 2388 if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
2326 2389
2327 InstallNativeFunctions(); 2390 InstallNativeFunctions();
2328 2391
2329 auto function_cache = 2392 auto function_cache =
2330 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize); 2393 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize);
2331 native_context()->set_function_cache(*function_cache); 2394 native_context()->set_function_cache(*function_cache);
2332 2395
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 static const char* harmony_new_target_natives[] = {nullptr}; 2565 static const char* harmony_new_target_natives[] = {nullptr};
2503 2566
2504 for (int i = ExperimentalNatives::GetDebuggerCount(); 2567 for (int i = ExperimentalNatives::GetDebuggerCount();
2505 i < ExperimentalNatives::GetBuiltinsCount(); i++) { 2568 i < ExperimentalNatives::GetBuiltinsCount(); i++) {
2506 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ 2569 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
2507 if (FLAG_##id) { \ 2570 if (FLAG_##id) { \
2508 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ 2571 for (size_t j = 0; id##_natives[j] != NULL; j++) { \
2509 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ 2572 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
2510 if (strncmp(script_name.start(), id##_natives[j], \ 2573 if (strncmp(script_name.start(), id##_natives[j], \
2511 script_name.length()) == 0) { \ 2574 script_name.length()) == 0) { \
2512 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ 2575 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
2576 return false; \
2577 } \
2513 } \ 2578 } \
2514 } \ 2579 } \
2515 } 2580 }
2516 HARMONY_INPROGRESS(INSTALL_EXPERIMENTAL_NATIVES); 2581 HARMONY_INPROGRESS(INSTALL_EXPERIMENTAL_NATIVES);
2517 HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); 2582 HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES);
2518 HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES); 2583 HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES);
2519 #undef INSTALL_EXPERIMENTAL_NATIVES 2584 #undef INSTALL_EXPERIMENTAL_NATIVES
2520 } 2585 }
2521 2586
2522 if (!CallUtilsFunction(isolate(), "PostExperimentals")) return false; 2587 if (!CallUtilsFunction(isolate(), "PostExperimentals")) return false;
2523 2588
2524 InstallExperimentalNativeFunctions(); 2589 InstallExperimentalNativeFunctions();
2525 InstallExperimentalBuiltinFunctionIds(); 2590 InstallExperimentalBuiltinFunctionIds();
2526 return true; 2591 return true;
2527 } 2592 }
2528 2593
2529 2594
2530 bool Genesis::InstallExtraNatives() { 2595 bool Genesis::InstallExtraNatives() {
2531 for (int i = ExtraNatives::GetDebuggerCount(); 2596 for (int i = ExtraNatives::GetDebuggerCount();
2532 i < ExtraNatives::GetBuiltinsCount(); i++) { 2597 i < ExtraNatives::GetBuiltinsCount(); i++) {
2533 if (!CompileExtraBuiltin(isolate(), i)) return false; 2598 if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false;
2534 } 2599 }
2535 2600
2536 return true; 2601 return true;
2602 }
2603
2604
2605 bool Bootstrapper::InstallCodeStubNatives(Isolate* isolate) {
2606 for (int i = CodeStubNatives::GetDebuggerCount();
2607 i < CodeStubNatives::GetBuiltinsCount(); i++) {
2608 if (!CompileCodeStubBuiltin(isolate, i)) return false;
2609 }
2610
2611 return true;
2537 } 2612 }
2538 2613
2539 2614
2540 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 2615 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
2541 const char* function_name, 2616 const char* function_name,
2542 BuiltinFunctionId id) { 2617 BuiltinFunctionId id) {
2543 Isolate* isolate = holder->GetIsolate(); 2618 Isolate* isolate = holder->GetIsolate();
2544 Handle<Object> function_object = 2619 Handle<Object> function_object =
2545 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); 2620 Object::GetProperty(isolate, holder, function_name).ToHandleChecked();
2546 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); 2621 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 3147
3073 private: 3148 private:
3074 bool flag_; 3149 bool flag_;
3075 bool enabled_; 3150 bool enabled_;
3076 }; 3151 };
3077 3152
3078 3153
3079 Genesis::Genesis(Isolate* isolate, 3154 Genesis::Genesis(Isolate* isolate,
3080 MaybeHandle<JSGlobalProxy> maybe_global_proxy, 3155 MaybeHandle<JSGlobalProxy> maybe_global_proxy,
3081 v8::Local<v8::ObjectTemplate> global_proxy_template, 3156 v8::Local<v8::ObjectTemplate> global_proxy_template,
3082 v8::ExtensionConfiguration* extensions) 3157 v8::ExtensionConfiguration* extensions,
3158 ContextType context_type)
3083 : isolate_(isolate), active_(isolate->bootstrapper()) { 3159 : isolate_(isolate), active_(isolate->bootstrapper()) {
3084 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); 3160 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
3085 result_ = Handle<Context>::null(); 3161 result_ = Handle<Context>::null();
3086 // Before creating the roots we must save the context and restore it 3162 // Before creating the roots we must save the context and restore it
3087 // on all function exits. 3163 // on all function exits.
3088 SaveContext saved_context(isolate); 3164 SaveContext saved_context(isolate);
3089 3165
3090 // During genesis, the boilerplate for stack overflow won't work until the 3166 // During genesis, the boilerplate for stack overflow won't work until the
3091 // environment has been at least partially initialized. Add a stack check 3167 // environment has been at least partially initialized. Add a stack check
3092 // before entering JS code to catch overflow early. 3168 // before entering JS code to catch overflow early.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3216 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3141 } else { 3217 } else {
3142 // We get here if there was no context snapshot. 3218 // We get here if there was no context snapshot.
3143 CreateRoots(); 3219 CreateRoots();
3144 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3220 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3145 CreateStrictModeFunctionMaps(empty_function); 3221 CreateStrictModeFunctionMaps(empty_function);
3146 CreateStrongModeFunctionMaps(empty_function); 3222 CreateStrongModeFunctionMaps(empty_function);
3147 Handle<GlobalObject> global_object = 3223 Handle<GlobalObject> global_object =
3148 CreateNewGlobals(global_proxy_template, global_proxy); 3224 CreateNewGlobals(global_proxy_template, global_proxy);
3149 HookUpGlobalProxy(global_object, global_proxy); 3225 HookUpGlobalProxy(global_object, global_proxy);
3150 InitializeGlobal(global_object, empty_function); 3226 InitializeGlobal(global_object, empty_function, context_type);
3151 InstallJSFunctionResultCaches(); 3227 InstallJSFunctionResultCaches();
3152 InitializeNormalizedMapCaches(); 3228 InitializeNormalizedMapCaches();
3153 if (!InstallNatives()) return; 3229
3230 if (!InstallNatives(context_type)) return;
3154 3231
3155 MakeFunctionInstancePrototypeWritable(); 3232 MakeFunctionInstancePrototypeWritable();
3156 3233
3157 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3234 if (context_type == FULL_CONTEXT) {
3235 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3236 }
3158 isolate->counters()->contexts_created_from_scratch()->Increment(); 3237 isolate->counters()->contexts_created_from_scratch()->Increment();
3159 } 3238 }
3160 3239
3161 // Install experimental and extra natives. Do not include them into the 3240 // Install experimental and extra natives. Do not include them into the
3162 // snapshot as we should be able to turn them off at runtime. Re-installing 3241 // snapshot as we should be able to turn them off at runtime. Re-installing
3163 // them after they have already been deserialized would also fail. 3242 // them after they have already been deserialized would also fail.
3164 if (!isolate->serializer_enabled()) { 3243 if (context_type == FULL_CONTEXT) {
3165 InitializeExperimentalGlobal(); 3244 if (!isolate->serializer_enabled()) {
3166 if (!InstallExperimentalNatives()) return; 3245 InitializeExperimentalGlobal();
3167 if (!InstallExtraNatives()) return; 3246 if (!InstallExperimentalNatives()) return;
3247 if (!InstallExtraNatives()) return;
3248 }
3249
3250 // The serializer cannot serialize typed arrays. Reset those typed arrays
3251 // for each new context.
3252 InitializeBuiltinTypedArrays();
3168 } 3253 }
3169 3254
3170 // The serializer cannot serialize typed arrays. Reset those typed arrays
3171 // for each new context.
3172 InitializeBuiltinTypedArrays();
3173
3174 result_ = native_context(); 3255 result_ = native_context();
3175 } 3256 }
3176 3257
3177 3258
3178 // Support for thread preemption. 3259 // Support for thread preemption.
3179 3260
3180 // Reserve space for statics needing saving and restoring. 3261 // Reserve space for statics needing saving and restoring.
3181 int Bootstrapper::ArchiveSpacePerThread() { 3262 int Bootstrapper::ArchiveSpacePerThread() {
3182 return sizeof(NestingCounterType); 3263 return sizeof(NestingCounterType);
3183 } 3264 }
(...skipping 14 matching lines...) Expand all
3198 } 3279 }
3199 3280
3200 3281
3201 // Called when the top-level V8 mutex is destroyed. 3282 // Called when the top-level V8 mutex is destroyed.
3202 void Bootstrapper::FreeThreadResources() { 3283 void Bootstrapper::FreeThreadResources() {
3203 DCHECK(!IsActive()); 3284 DCHECK(!IsActive());
3204 } 3285 }
3205 3286
3206 } // namespace internal 3287 } // namespace internal
3207 } // namespace v8 3288 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698