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

Side by Side Diff: src/bootstrapper.cc

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