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

Side by Side Diff: src/bootstrapper.cc

Issue 1480003002: [runtime] Replace global object link with native context link in all contexts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add patch from Orion for interpreter cementation test. Disable obsolete/invalid tests. Created 5 years 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/arm64/macro-assembler-arm64.cc ('k') | src/code-stubs-hydrogen.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/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/extensions/externalize-string-extension.h" 10 #include "src/extensions/externalize-string-extension.h"
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 } 1045 }
1046 1046
1047 1047
1048 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object, 1048 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object,
1049 Handle<FixedArray> outdated_contexts) { 1049 Handle<FixedArray> outdated_contexts) {
1050 Handle<JSGlobalObject> global_object_from_snapshot( 1050 Handle<JSGlobalObject> global_object_from_snapshot(
1051 JSGlobalObject::cast(native_context()->extension())); 1051 JSGlobalObject::cast(native_context()->extension()));
1052 native_context()->set_extension(*global_object); 1052 native_context()->set_extension(*global_object);
1053 native_context()->set_security_token(*global_object); 1053 native_context()->set_security_token(*global_object);
1054 1054
1055 // Replace outdated global objects in deserialized contexts.
1056 for (int i = 0; i < outdated_contexts->length(); ++i) {
1057 Context* context = Context::cast(outdated_contexts->get(i));
1058 // Assert that there is only one native context.
1059 DCHECK(!context->IsNativeContext() || context == *native_context());
1060 DCHECK_EQ(context->global_object(), *global_object_from_snapshot);
1061 context->set_global_object(*global_object);
1062 }
1063
1064 TransferNamedProperties(global_object_from_snapshot, global_object); 1055 TransferNamedProperties(global_object_from_snapshot, global_object);
1065 TransferIndexedProperties(global_object_from_snapshot, global_object); 1056 TransferIndexedProperties(global_object_from_snapshot, global_object);
1066 } 1057 }
1067 1058
1068 1059
1069 // This is only called if we are not using snapshots. The equivalent 1060 // This is only called if we are not using snapshots. The equivalent
1070 // work in the snapshot case is done in HookUpGlobalObject. 1061 // work in the snapshot case is done in HookUpGlobalObject.
1071 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, 1062 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
1072 Handle<JSFunction> empty_function, 1063 Handle<JSFunction> empty_function,
1073 ContextType context_type) { 1064 ContextType context_type) {
1074 // --- N a t i v e C o n t e x t --- 1065 // --- N a t i v e C o n t e x t ---
1075 // Use the empty function as closure (no scope info). 1066 // Use the empty function as closure (no scope info).
1076 native_context()->set_closure(*empty_function); 1067 native_context()->set_closure(*empty_function);
1077 native_context()->set_previous(NULL); 1068 native_context()->set_previous(NULL);
1078 // Set extension and global object. 1069 // Set extension and global object.
1079 native_context()->set_extension(*global_object); 1070 native_context()->set_extension(*global_object);
1080 native_context()->set_global_object(*global_object);
1081 // Security setup: Set the security token of the native context to the global 1071 // Security setup: Set the security token of the native context to the global
1082 // object. This makes the security check between two different contexts fail 1072 // object. This makes the security check between two different contexts fail
1083 // by default even in case of global object reinitialization. 1073 // by default even in case of global object reinitialization.
1084 native_context()->set_security_token(*global_object); 1074 native_context()->set_security_token(*global_object);
1085 1075
1086 Isolate* isolate = global_object->GetIsolate(); 1076 Isolate* isolate = global_object->GetIsolate();
1087 Factory* factory = isolate->factory(); 1077 Factory* factory = isolate->factory();
1088 1078
1089 Handle<ScriptContextTable> script_context_table = 1079 Handle<ScriptContextTable> script_context_table =
1090 factory->NewScriptContextTable(); 1080 factory->NewScriptContextTable();
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 Handle<String> script_name = 1606 Handle<String> script_name =
1617 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); 1607 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
1618 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( 1608 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript(
1619 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), 1609 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
1620 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, 1610 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE,
1621 false); 1611 false);
1622 if (function_info.is_null()) return false; 1612 if (function_info.is_null()) return false;
1623 1613
1624 DCHECK(context->IsNativeContext()); 1614 DCHECK(context->IsNativeContext());
1625 1615
1626 Handle<Context> runtime_context(context->runtime_context());
1627 Handle<JSFunction> fun = 1616 Handle<JSFunction> fun =
1628 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, 1617 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
1629 runtime_context); 1618 context);
1630 Handle<Object> receiver = isolate->factory()->undefined_value(); 1619 Handle<Object> receiver = isolate->factory()->undefined_value();
1631 1620
1632 // For non-extension scripts, run script to get the function wrapper. 1621 // For non-extension scripts, run script to get the function wrapper.
1633 Handle<Object> wrapper; 1622 Handle<Object> wrapper;
1634 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) { 1623 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
1635 return false; 1624 return false;
1636 } 1625 }
1637 // Then run the function wrapper. 1626 // Then run the function wrapper.
1638 return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver, 1627 return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver,
1639 argc, argv).is_null(); 1628 argc, argv).is_null();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 Handle<JSObject> global = isolate()->global_object(); 1735 Handle<JSObject> global = isolate()->global_object();
1747 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM); 1736 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM);
1748 break; 1737 break;
1749 } 1738 }
1750 case THIN_CONTEXT: 1739 case THIN_CONTEXT:
1751 break; 1740 break;
1752 } 1741 }
1753 1742
1754 // The utils object can be removed for cases that reach this point. 1743 // The utils object can be removed for cases that reach this point.
1755 native_context()->set_natives_utils_object(heap()->undefined_value()); 1744 native_context()->set_natives_utils_object(heap()->undefined_value());
1756
1757 #ifdef DEBUG
1758 JSGlobalObject* dummy = native_context()->runtime_context()->global_object();
1759 DCHECK_EQ(0, dummy->elements()->length());
1760 DCHECK_EQ(0, GlobalDictionary::cast(dummy->properties())->NumberOfElements());
1761 #endif
1762 } 1745 }
1763 1746
1764 1747
1765 void Bootstrapper::ExportFromRuntime(Isolate* isolate, 1748 void Bootstrapper::ExportFromRuntime(Isolate* isolate,
1766 Handle<JSObject> container) { 1749 Handle<JSObject> container) {
1767 Factory* factory = isolate->factory(); 1750 Factory* factory = isolate->factory();
1768 HandleScope scope(isolate); 1751 HandleScope scope(isolate);
1769 Handle<Context> native_context = isolate->native_context(); 1752 Handle<Context> native_context = isolate->native_context();
1770 #define EXPORT_PRIVATE_SYMBOL(NAME) \ 1753 #define EXPORT_PRIVATE_SYMBOL(NAME) \
1771 Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \ 1754 Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 initial_map->AppendDescriptor(&d); 2219 initial_map->AppendDescriptor(&d);
2237 } 2220 }
2238 2221
2239 return array_function; 2222 return array_function;
2240 } 2223 }
2241 2224
2242 2225
2243 bool Genesis::InstallNatives(ContextType context_type) { 2226 bool Genesis::InstallNatives(ContextType context_type) {
2244 HandleScope scope(isolate()); 2227 HandleScope scope(isolate());
2245 2228
2246 // Create a bridge function that has context in the native context.
2247 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string());
2248 DCHECK(bridge->context() == *isolate()->native_context());
2249
2250 // Allocate the runtime context.
2251 {
2252 Handle<Context> context =
2253 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
2254 native_context()->set_runtime_context(*context);
2255 Handle<Code> code = isolate()->builtins()->Illegal();
2256 Handle<JSFunction> global_fun =
2257 factory()->NewFunction(factory()->empty_string(), code,
2258 JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize);
2259 global_fun->initial_map()->set_dictionary_map(true);
2260 global_fun->initial_map()->set_prototype(heap()->null_value());
2261 Handle<JSGlobalObject> dummy_global =
2262 Handle<JSGlobalObject>::cast(factory()->NewJSGlobalObject(global_fun));
2263 dummy_global->set_native_context(*native_context());
2264 dummy_global->set_global_proxy(native_context()->global_proxy());
2265 context->set_global_object(*dummy_global);
2266 // Something went wrong if we actually need to write into the dummy global.
2267 dummy_global->set_properties(*GlobalDictionary::New(isolate(), 0));
2268 dummy_global->set_elements(heap()->empty_fixed_array());
2269 }
2270
2271 // Set up the utils object as shared container between native scripts. 2229 // Set up the utils object as shared container between native scripts.
2272 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); 2230 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
2273 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, 2231 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
2274 "utils container for native scripts"); 2232 "utils container for native scripts");
2275 native_context()->set_natives_utils_object(*utils); 2233 native_context()->set_natives_utils_object(*utils);
2276 2234
2277 // Set up the extras utils object as a shared container between native 2235 // Set up the extras utils object as a shared container between native
2278 // scripts and extras. (Extras consume things added there by native scripts.) 2236 // scripts and extras. (Extras consume things added there by native scripts.)
2279 Handle<JSObject> extras_utils = 2237 Handle<JSObject> extras_utils =
2280 factory()->NewJSObject(isolate()->object_function()); 2238 factory()->NewJSObject(isolate()->object_function());
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
3184 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3142 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3185 CreateStrictModeFunctionMaps(empty_function); 3143 CreateStrictModeFunctionMaps(empty_function);
3186 CreateStrongModeFunctionMaps(empty_function); 3144 CreateStrongModeFunctionMaps(empty_function);
3187 CreateIteratorMaps(); 3145 CreateIteratorMaps();
3188 Handle<JSGlobalObject> global_object = 3146 Handle<JSGlobalObject> global_object =
3189 CreateNewGlobals(global_proxy_template, global_proxy); 3147 CreateNewGlobals(global_proxy_template, global_proxy);
3190 HookUpGlobalProxy(global_object, global_proxy); 3148 HookUpGlobalProxy(global_object, global_proxy);
3191 InitializeGlobal(global_object, empty_function, context_type); 3149 InitializeGlobal(global_object, empty_function, context_type);
3192 InitializeNormalizedMapCaches(); 3150 InitializeNormalizedMapCaches();
3193 3151
3152 // TODO(yangguo): Find a way to prevent accidentially installing properties
3153 // on the global object.
3194 if (!InstallNatives(context_type)) return; 3154 if (!InstallNatives(context_type)) return;
3195 3155
3196 MakeFunctionInstancePrototypeWritable(); 3156 MakeFunctionInstancePrototypeWritable();
3197 3157
3198 if (context_type != THIN_CONTEXT) { 3158 if (context_type != THIN_CONTEXT) {
3199 if (!InstallExtraNatives()) return; 3159 if (!InstallExtraNatives()) return;
3200 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3160 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3201 } 3161 }
3202 isolate->counters()->contexts_created_from_scratch()->Increment(); 3162 isolate->counters()->contexts_created_from_scratch()->Increment();
3203 // Re-initialize the counter because it got incremented during snapshot 3163 // Re-initialize the counter because it got incremented during snapshot
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3260 } 3220 }
3261 3221
3262 3222
3263 // Called when the top-level V8 mutex is destroyed. 3223 // Called when the top-level V8 mutex is destroyed.
3264 void Bootstrapper::FreeThreadResources() { 3224 void Bootstrapper::FreeThreadResources() {
3265 DCHECK(!IsActive()); 3225 DCHECK(!IsActive());
3266 } 3226 }
3267 3227
3268 } // namespace internal 3228 } // namespace internal
3269 } // namespace v8 3229 } // namespace v8
OLDNEW
« no previous file with comments | « src/arm64/macro-assembler-arm64.cc ('k') | src/code-stubs-hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698