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

Side by Side Diff: src/bootstrapper.cc

Issue 1129743003: Make V8 extras a separate type of native (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Initial version from https://codereview.chromium.org/1129743003 Created 5 years, 7 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 | « BUILD.gn ('k') | src/heap/heap.h » ('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 24 matching lines...) Expand all
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
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
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
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
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);
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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); 2367 HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES);
2350 HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES); 2368 HARMONY_SHIPPING(INSTALL_EXPERIMENTAL_NATIVES);
2351 #undef INSTALL_EXPERIMENTAL_NATIVES 2369 #undef INSTALL_EXPERIMENTAL_NATIVES
2352 } 2370 }
2353 2371
2354 InstallExperimentalNativeFunctions(); 2372 InstallExperimentalNativeFunctions();
2355 return true; 2373 return true;
2356 } 2374 }
2357 2375
2358 2376
2377 bool Genesis::InstallExtraNatives() {
2378 for (int i = ExtraNatives::GetDebuggerCount();
2379 i < ExtraNatives::GetBuiltinsCount(); i++) {
2380 if (!CompileExtraBuiltin(isolate(), i)) return false;
2381 }
2382
2383 return true;
2384 }
2385
2386
2359 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 2387 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
2360 const char* function_name, 2388 const char* function_name,
2361 BuiltinFunctionId id) { 2389 BuiltinFunctionId id) {
2362 Isolate* isolate = holder->GetIsolate(); 2390 Isolate* isolate = holder->GetIsolate();
2363 Handle<Object> function_object = 2391 Handle<Object> function_object =
2364 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); 2392 Object::GetProperty(isolate, holder, function_name).ToHandleChecked();
2365 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); 2393 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
2366 function->shared()->set_function_data(Smi::FromInt(id)); 2394 function->shared()->set_function_data(Smi::FromInt(id));
2367 } 2395 }
2368 2396
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2922 InstallJSFunctionResultCaches(); 2950 InstallJSFunctionResultCaches();
2923 InitializeNormalizedMapCaches(); 2951 InitializeNormalizedMapCaches();
2924 if (!InstallNatives()) return; 2952 if (!InstallNatives()) return;
2925 2953
2926 MakeFunctionInstancePrototypeWritable(); 2954 MakeFunctionInstancePrototypeWritable();
2927 2955
2928 if (!ConfigureGlobalObjects(global_proxy_template)) return; 2956 if (!ConfigureGlobalObjects(global_proxy_template)) return;
2929 isolate->counters()->contexts_created_from_scratch()->Increment(); 2957 isolate->counters()->contexts_created_from_scratch()->Increment();
2930 } 2958 }
2931 2959
2932 // Install experimental natives. Do not include them into the snapshot as we 2960 // Install experimental and extra natives. Do not include them into the
2933 // should be able to turn them off at runtime. Re-installing them after 2961 // snapshot as we should be able to turn them off at runtime. Re-installing
2934 // they have already been deserialized would also fail. 2962 // them after they have already been deserialized would also fail.
2935 if (!isolate->serializer_enabled()) { 2963 if (!isolate->serializer_enabled()) {
2936 InitializeExperimentalGlobal(); 2964 InitializeExperimentalGlobal();
2937 if (!InstallExperimentalNatives()) return; 2965 if (!InstallExperimentalNatives()) return;
2966 if (!InstallExtraNatives()) return;
2938 } 2967 }
2939 2968
2940 // The serializer cannot serialize typed arrays. Reset those typed arrays 2969 // The serializer cannot serialize typed arrays. Reset those typed arrays
2941 // for each new context. 2970 // for each new context.
2942 InitializeBuiltinTypedArrays(); 2971 InitializeBuiltinTypedArrays();
2943 2972
2944 result_ = native_context(); 2973 result_ = native_context();
2945 } 2974 }
2946 2975
2947 2976
(...skipping 19 matching lines...) Expand all
2967 return from + sizeof(NestingCounterType); 2996 return from + sizeof(NestingCounterType);
2968 } 2997 }
2969 2998
2970 2999
2971 // Called when the top-level V8 mutex is destroyed. 3000 // Called when the top-level V8 mutex is destroyed.
2972 void Bootstrapper::FreeThreadResources() { 3001 void Bootstrapper::FreeThreadResources() {
2973 DCHECK(!IsActive()); 3002 DCHECK(!IsActive());
2974 } 3003 }
2975 3004
2976 } } // namespace v8::internal 3005 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698