OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
35 return heap->natives_source_cache(); | 35 return heap->natives_source_cache(); |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 template <> | 39 template <> |
40 FixedArray* GetCache<ExperimentalNatives>(Heap* heap) { | 40 FixedArray* GetCache<ExperimentalNatives>(Heap* heap) { |
41 return heap->experimental_natives_source_cache(); | 41 return heap->experimental_natives_source_cache(); |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 template <> | |
46 FixedArray* GetCache<ExtraNatives>(Heap* heap) { | |
47 return heap->extra_natives_source_cache(); | |
48 } | |
49 | |
50 | |
45 template <class Source> | 51 template <class Source> |
46 Handle<String> Bootstrapper::SourceLookup(int index) { | 52 Handle<String> Bootstrapper::SourceLookup(int index) { |
47 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); | 53 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); |
48 Heap* heap = isolate_->heap(); | 54 Heap* heap = isolate_->heap(); |
49 if (GetCache<Source>(heap)->get(index)->IsUndefined()) { | 55 if (GetCache<Source>(heap)->get(index)->IsUndefined()) { |
50 // We can use external strings for the natives. | 56 // We can use external strings for the natives. |
51 Vector<const char> source = Source::GetScriptSource(index); | 57 Vector<const char> source = Source::GetScriptSource(index); |
52 NativesExternalStringResource* resource = | 58 NativesExternalStringResource* resource = |
53 new NativesExternalStringResource(source.start(), source.length()); | 59 new NativesExternalStringResource(source.start(), source.length()); |
54 // We do not expect this to throw an exception. Change this if it does. | 60 // We do not expect this to throw an exception. Change this if it does. |
55 Handle<String> source_code = isolate_->factory() | 61 Handle<String> source_code = isolate_->factory() |
56 ->NewExternalStringFromOneByte(resource) | 62 ->NewExternalStringFromOneByte(resource) |
57 .ToHandleChecked(); | 63 .ToHandleChecked(); |
58 // Mark this external string with a special map. | 64 // Mark this external string with a special map. |
59 source_code->set_map(isolate_->heap()->native_source_string_map()); | 65 source_code->set_map(isolate_->heap()->native_source_string_map()); |
60 GetCache<Source>(heap)->set(index, *source_code); | 66 GetCache<Source>(heap)->set(index, *source_code); |
61 } | 67 } |
62 Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_); | 68 Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_); |
63 return Handle<String>::cast(cached_source); | 69 return Handle<String>::cast(cached_source); |
64 } | 70 } |
65 | 71 |
66 | 72 |
67 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); | 73 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); |
68 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( | 74 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( |
69 int index); | 75 int index); |
76 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); | |
70 | 77 |
71 | 78 |
72 void Bootstrapper::Initialize(bool create_heap_objects) { | 79 void Bootstrapper::Initialize(bool create_heap_objects) { |
73 extensions_cache_.Initialize(isolate_, create_heap_objects); | 80 extensions_cache_.Initialize(isolate_, create_heap_objects); |
74 } | 81 } |
75 | 82 |
76 | 83 |
77 static const char* GCFunctionName() { | 84 static const char* GCFunctionName() { |
78 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; | 85 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; |
79 return flag_given ? FLAG_expose_gc_as : "gc"; | 86 return flag_given ? FLAG_expose_gc_as : "gc"; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 delete resource; | 134 delete resource; |
128 } | 135 } |
129 } | 136 } |
130 } | 137 } |
131 } | 138 } |
132 | 139 |
133 | 140 |
134 void Bootstrapper::TearDown() { | 141 void Bootstrapper::TearDown() { |
135 DeleteNativeSources(isolate_->heap()->natives_source_cache()); | 142 DeleteNativeSources(isolate_->heap()->natives_source_cache()); |
136 DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache()); | 143 DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache()); |
144 DeleteNativeSources(isolate_->heap()->extra_natives_source_cache()); | |
137 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 145 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
138 } | 146 } |
139 | 147 |
140 | 148 |
141 class Genesis BASE_EMBEDDED { | 149 class Genesis BASE_EMBEDDED { |
142 public: | 150 public: |
143 Genesis(Isolate* isolate, | 151 Genesis(Isolate* isolate, |
144 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 152 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
145 v8::Handle<v8::ObjectTemplate> global_proxy_template, | 153 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
146 v8::ExtensionConfiguration* extensions); | 154 v8::ExtensionConfiguration* extensions); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 const char* name, | 221 const char* name, |
214 ElementsKind elements_kind); | 222 ElementsKind elements_kind); |
215 bool InstallNatives(); | 223 bool InstallNatives(); |
216 | 224 |
217 void InstallTypedArray( | 225 void InstallTypedArray( |
218 const char* name, | 226 const char* name, |
219 ElementsKind elements_kind, | 227 ElementsKind elements_kind, |
220 Handle<JSFunction>* fun, | 228 Handle<JSFunction>* fun, |
221 Handle<Map>* external_map); | 229 Handle<Map>* external_map); |
222 bool InstallExperimentalNatives(); | 230 bool InstallExperimentalNatives(); |
231 bool InstallExtraNatives(); | |
223 void InstallBuiltinFunctionIds(); | 232 void InstallBuiltinFunctionIds(); |
224 void InstallJSFunctionResultCaches(); | 233 void InstallJSFunctionResultCaches(); |
225 void InitializeNormalizedMapCaches(); | 234 void InitializeNormalizedMapCaches(); |
226 | 235 |
227 enum ExtensionTraversalState { | 236 enum ExtensionTraversalState { |
228 UNVISITED, VISITED, INSTALLED | 237 UNVISITED, VISITED, INSTALLED |
229 }; | 238 }; |
230 | 239 |
231 class ExtensionStates { | 240 class ExtensionStates { |
232 public: | 241 public: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, | 302 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, |
294 bool is_constructor); | 303 bool is_constructor); |
295 | 304 |
296 | 305 |
297 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, | 306 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
298 FunctionMode function_mode); | 307 FunctionMode function_mode); |
299 void SetStrongFunctionInstanceDescriptor(Handle<Map> map); | 308 void SetStrongFunctionInstanceDescriptor(Handle<Map> map); |
300 | 309 |
301 static bool CompileBuiltin(Isolate* isolate, int index); | 310 static bool CompileBuiltin(Isolate* isolate, int index); |
302 static bool CompileExperimentalBuiltin(Isolate* isolate, int index); | 311 static bool CompileExperimentalBuiltin(Isolate* isolate, int index); |
312 static bool CompileExtraBuiltin(Isolate* isolate, int index); | |
303 static bool CompileNative(Isolate* isolate, | 313 static bool CompileNative(Isolate* isolate, |
304 Vector<const char> name, | 314 Vector<const char> name, |
305 Handle<String> source); | 315 Handle<String> source); |
306 static bool CompileScriptCached(Isolate* isolate, | 316 static bool CompileScriptCached(Isolate* isolate, |
307 Vector<const char> name, | 317 Vector<const char> name, |
308 Handle<String> source, | 318 Handle<String> source, |
309 SourceCodeCache* cache, | 319 SourceCodeCache* cache, |
310 v8::Extension* extension, | 320 v8::Extension* extension, |
311 Handle<Context> top_context, | 321 Handle<Context> top_context, |
312 bool use_runtime_context); | 322 bool use_runtime_context); |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1440 | 1450 |
1441 | 1451 |
1442 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { | 1452 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { |
1443 Vector<const char> name = ExperimentalNatives::GetScriptName(index); | 1453 Vector<const char> name = ExperimentalNatives::GetScriptName(index); |
1444 Handle<String> source_code = | 1454 Handle<String> source_code = |
1445 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); | 1455 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); |
1446 return CompileNative(isolate, name, source_code); | 1456 return CompileNative(isolate, name, source_code); |
1447 } | 1457 } |
1448 | 1458 |
1449 | 1459 |
1460 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) { | |
1461 Vector<const char> name = ExtraNatives::GetScriptName(index); | |
1462 Handle<String> source_code = | |
1463 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); | |
1464 return CompileNative(isolate, name, source_code); | |
jochen (gone - plz use gerrit)
2015/05/07 09:56:30
CompileNative calls CompileScriptCached with use_r
| |
1465 } | |
1466 | |
1467 | |
1450 bool Genesis::CompileNative(Isolate* isolate, | 1468 bool Genesis::CompileNative(Isolate* isolate, |
1451 Vector<const char> name, | 1469 Vector<const char> name, |
1452 Handle<String> source) { | 1470 Handle<String> source) { |
1453 HandleScope scope(isolate); | 1471 HandleScope scope(isolate); |
1454 SuppressDebug compiling_natives(isolate->debug()); | 1472 SuppressDebug compiling_natives(isolate->debug()); |
1455 // During genesis, the boilerplate for stack overflow won't work until the | 1473 // During genesis, the boilerplate for stack overflow won't work until the |
1456 // environment has been at least partially initialized. Add a stack check | 1474 // environment has been at least partially initialized. Add a stack check |
1457 // before entering JS code to catch overflow early. | 1475 // before entering JS code to catch overflow early. |
1458 StackLimitCheck check(isolate); | 1476 StackLimitCheck check(isolate); |
1459 if (check.HasOverflowed()) return false; | 1477 if (check.HasOverflowed()) return false; |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2345 HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); | 2363 HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); |
2346 HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES); | 2364 HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES); |
2347 #undef INSTALL_EXPERIMENTAL_NATIVES | 2365 #undef INSTALL_EXPERIMENTAL_NATIVES |
2348 } | 2366 } |
2349 | 2367 |
2350 InstallExperimentalNativeFunctions(); | 2368 InstallExperimentalNativeFunctions(); |
2351 return true; | 2369 return true; |
2352 } | 2370 } |
2353 | 2371 |
2354 | 2372 |
2373 bool Genesis::InstallExtraNatives() { | |
2374 for (int i = ExtraNatives::GetDebuggerCount(); | |
2375 i < ExtraNatives::GetBuiltinsCount(); i++) { | |
2376 if (!CompileExtraBuiltin(isolate(), i)) return false; | |
2377 } | |
2378 | |
2379 return true; | |
2380 } | |
2381 | |
2382 | |
2355 static void InstallBuiltinFunctionId(Handle<JSObject> holder, | 2383 static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
2356 const char* function_name, | 2384 const char* function_name, |
2357 BuiltinFunctionId id) { | 2385 BuiltinFunctionId id) { |
2358 Isolate* isolate = holder->GetIsolate(); | 2386 Isolate* isolate = holder->GetIsolate(); |
2359 Handle<Object> function_object = | 2387 Handle<Object> function_object = |
2360 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); | 2388 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); |
2361 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); | 2389 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); |
2362 function->shared()->set_function_data(Smi::FromInt(id)); | 2390 function->shared()->set_function_data(Smi::FromInt(id)); |
2363 } | 2391 } |
2364 | 2392 |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2918 InstallJSFunctionResultCaches(); | 2946 InstallJSFunctionResultCaches(); |
2919 InitializeNormalizedMapCaches(); | 2947 InitializeNormalizedMapCaches(); |
2920 if (!InstallNatives()) return; | 2948 if (!InstallNatives()) return; |
2921 | 2949 |
2922 MakeFunctionInstancePrototypeWritable(); | 2950 MakeFunctionInstancePrototypeWritable(); |
2923 | 2951 |
2924 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 2952 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
2925 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2953 isolate->counters()->contexts_created_from_scratch()->Increment(); |
2926 } | 2954 } |
2927 | 2955 |
2928 // Install experimental natives. Do not include them into the snapshot as we | 2956 // Install experimental and extra natives. Do not include them into the |
2929 // should be able to turn them off at runtime. Re-installing them after | 2957 // snapshot as we should be able to turn them off at runtime. Re-installing |
2930 // they have already been deserialized would also fail. | 2958 // them after they have already been deserialized would also fail. |
2931 if (!isolate->serializer_enabled()) { | 2959 if (!isolate->serializer_enabled()) { |
2932 InitializeExperimentalGlobal(); | 2960 InitializeExperimentalGlobal(); |
2933 if (!InstallExperimentalNatives()) return; | 2961 if (!InstallExperimentalNatives()) return; |
2962 if (!InstallExtraNatives()) return; | |
2934 } | 2963 } |
2935 | 2964 |
2936 // The serializer cannot serialize typed arrays. Reset those typed arrays | 2965 // The serializer cannot serialize typed arrays. Reset those typed arrays |
2937 // for each new context. | 2966 // for each new context. |
2938 InitializeBuiltinTypedArrays(); | 2967 InitializeBuiltinTypedArrays(); |
2939 | 2968 |
2940 result_ = native_context(); | 2969 result_ = native_context(); |
2941 } | 2970 } |
2942 | 2971 |
2943 | 2972 |
(...skipping 19 matching lines...) Expand all Loading... | |
2963 return from + sizeof(NestingCounterType); | 2992 return from + sizeof(NestingCounterType); |
2964 } | 2993 } |
2965 | 2994 |
2966 | 2995 |
2967 // Called when the top-level V8 mutex is destroyed. | 2996 // Called when the top-level V8 mutex is destroyed. |
2968 void Bootstrapper::FreeThreadResources() { | 2997 void Bootstrapper::FreeThreadResources() { |
2969 DCHECK(!IsActive()); | 2998 DCHECK(!IsActive()); |
2970 } | 2999 } |
2971 | 3000 |
2972 } } // namespace v8::internal | 3001 } } // namespace v8::internal |
OLD | NEW |