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

Side by Side Diff: src/bootstrapper.cc

Issue 2761783002: Always run our fast array builtins. (Closed)
Patch Set: Make sure the strict map is used. Created 3 years, 9 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 | « no previous file | src/flag-definitions.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/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ 211 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \
212 void InitializeGlobal_##id(); 212 void InitializeGlobal_##id();
213 213
214 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) 214 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
215 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) 215 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
216 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) 216 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
217 #undef DECLARE_FEATURE_INITIALIZATION 217 #undef DECLARE_FEATURE_INITIALIZATION
218 218
219 void InstallOneBuiltinFunction(const char* object, const char* method, 219 void InstallOneBuiltinFunction(const char* object, const char* method,
220 Builtins::Name name); 220 Builtins::Name name);
221 void InitializeGlobal_enable_fast_array_builtins(); 221 void InitializeGlobal_experimental_fast_array_builtins();
222 222
223 Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, 223 Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
224 const char* name, Builtins::Name call, 224 const char* name, Builtins::Name call,
225 BuiltinFunctionId id, bool is_shared); 225 BuiltinFunctionId id, bool is_shared);
226 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, 226 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
227 const char* name, 227 const char* name,
228 ElementsKind elements_kind); 228 ElementsKind elements_kind);
229 bool InstallNatives(GlobalContextType context_type); 229 bool InstallNatives(GlobalContextType context_type);
230 230
231 void InstallTypedArray(const char* name, ElementsKind elements_kind, 231 void InstallTypedArray(const char* name, ElementsKind elements_kind,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 MaybeHandle<JSObject>(), call); 426 MaybeHandle<JSObject>(), call);
427 if (adapt) { 427 if (adapt) {
428 fun->shared()->set_internal_formal_parameter_count(len); 428 fun->shared()->set_internal_formal_parameter_count(len);
429 } else { 429 } else {
430 fun->shared()->DontAdaptArguments(); 430 fun->shared()->DontAdaptArguments();
431 } 431 }
432 fun->shared()->set_length(len); 432 fun->shared()->set_length(len);
433 return fun; 433 return fun;
434 } 434 }
435 435
436 Handle<JSFunction> InstallArrayBuiltinFunction(Handle<JSObject> base,
437 const char* name,
438 Builtins::Name call,
439 int argument_count) {
440 Isolate* isolate = base->GetIsolate();
441 Handle<String> str_name = isolate->factory()->InternalizeUtf8String(name);
442 Handle<JSFunction> fun =
443 CreateFunction(isolate, str_name, JS_OBJECT_TYPE, JSObject::kHeaderSize,
444 MaybeHandle<JSObject>(), call, true);
445 fun->shared()->set_internal_formal_parameter_count(argument_count);
446
447 // Set the length to 1 to satisfy ECMA-262.
448 fun->shared()->set_length(1);
449 fun->shared()->set_language_mode(STRICT);
450 InstallFunction(base, fun, str_name);
451 return fun;
452 }
453
436 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, 454 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
437 Handle<String> name, 455 Handle<String> name,
438 Builtins::Name call, int len, 456 Builtins::Name call, int len,
439 bool adapt, 457 bool adapt,
440 PropertyAttributes attrs = DONT_ENUM) { 458 PropertyAttributes attrs = DONT_ENUM) {
441 Handle<JSFunction> fun = 459 Handle<JSFunction> fun =
442 SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt); 460 SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt);
443 InstallFunction(base, fun, name, attrs); 461 InstallFunction(base, fun, name, attrs);
444 return fun; 462 return fun;
445 } 463 }
(...skipping 2613 matching lines...) Expand 10 before | Expand all | Expand 10 after
3059 3077
3060 3078
3061 void Genesis::InitializeExperimentalGlobal() { 3079 void Genesis::InitializeExperimentalGlobal() {
3062 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); 3080 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
3063 3081
3064 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) 3082 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
3065 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) 3083 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
3066 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) 3084 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
3067 #undef FEATURE_INITIALIZE_GLOBAL 3085 #undef FEATURE_INITIALIZE_GLOBAL
3068 3086
3069 InitializeGlobal_enable_fast_array_builtins(); 3087 InitializeGlobal_experimental_fast_array_builtins();
3070 } 3088 }
3071 3089
3072
3073 bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) { 3090 bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
3074 Vector<const char> name = Natives::GetScriptName(index); 3091 Vector<const char> name = Natives::GetScriptName(index);
3075 Handle<String> source_code = 3092 Handle<String> source_code =
3076 isolate->bootstrapper()->SourceLookup<Natives>(index); 3093 isolate->bootstrapper()->SourceLookup<Natives>(index);
3077 3094
3078 // We pass in extras_utils so that builtin code can set it up for later use 3095 // We pass in extras_utils so that builtin code can set it up for later use
3079 // by actual extras code, compiled with CompileExtraBuiltin. 3096 // by actual extras code, compiled with CompileExtraBuiltin.
3080 Handle<Object> global = isolate->global_object(); 3097 Handle<Object> global = isolate->global_object();
3081 Handle<Object> utils = isolate->natives_utils_object(); 3098 Handle<Object> utils = isolate->natives_utils_object();
3082 Handle<Object> extras_utils = isolate->extras_utils_object(); 3099 Handle<Object> extras_utils = isolate->extras_utils_object();
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
3682 3699
3683 LookupIterator it3(prototype, factory->NewStringFromAsciiChecked(method_name), 3700 LookupIterator it3(prototype, factory->NewStringFromAsciiChecked(method_name),
3684 LookupIterator::OWN_SKIP_INTERCEPTOR); 3701 LookupIterator::OWN_SKIP_INTERCEPTOR);
3685 Handle<Object> function = Object::GetProperty(&it3).ToHandleChecked(); 3702 Handle<Object> function = Object::GetProperty(&it3).ToHandleChecked();
3686 Handle<JSFunction>::cast(function)->set_code( 3703 Handle<JSFunction>::cast(function)->set_code(
3687 isolate->builtins()->builtin(builtin_name)); 3704 isolate->builtins()->builtin(builtin_name));
3688 Handle<JSFunction>::cast(function)->shared()->set_code( 3705 Handle<JSFunction>::cast(function)->shared()->set_code(
3689 isolate->builtins()->builtin(builtin_name)); 3706 isolate->builtins()->builtin(builtin_name));
3690 } 3707 }
3691 3708
3692 void Genesis::InitializeGlobal_enable_fast_array_builtins() { 3709 void Genesis::InitializeGlobal_experimental_fast_array_builtins() {
3693 if (!FLAG_enable_fast_array_builtins) return; 3710 if (!FLAG_experimental_fast_array_builtins) return;
3694 3711
3695 InstallOneBuiltinFunction("Array", "forEach", Builtins::kArrayForEach); 3712 // Insert experimental fast array builtins here.
3696 InstallOneBuiltinFunction("Array", "every", Builtins::kArrayEvery); 3713 InstallOneBuiltinFunction("Array", "filter", Builtins::kArrayFilter);
3697 InstallOneBuiltinFunction("Array", "some", Builtins::kArraySome);
3698 InstallOneBuiltinFunction("Array", "reduce", Builtins::kArrayReduce);
3699
3700 if (FLAG_experimental_array_builtins) {
3701 InstallOneBuiltinFunction("Array", "filter", Builtins::kArrayFilter);
3702 }
3703 } 3714 }
3704 3715
3705 void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { 3716 void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
3706 if (!FLAG_harmony_sharedarraybuffer) return; 3717 if (!FLAG_harmony_sharedarraybuffer) return;
3707 3718
3708 Handle<JSGlobalObject> global(native_context()->global_object()); 3719 Handle<JSGlobalObject> global(native_context()->global_object());
3709 Isolate* isolate = global->GetIsolate(); 3720 Isolate* isolate = global->GetIsolate();
3710 Factory* factory = isolate->factory(); 3721 Factory* factory = isolate->factory();
3711 3722
3712 Handle<JSFunction> shared_array_buffer_fun = 3723 Handle<JSFunction> shared_array_buffer_fun =
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
4136 } 4147 }
4137 4148
4138 // Install Global.isFinite 4149 // Install Global.isFinite
4139 SimpleInstallFunction(global_object, "isFinite", Builtins::kGlobalIsFinite, 1, 4150 SimpleInstallFunction(global_object, "isFinite", Builtins::kGlobalIsFinite, 1,
4140 true, kGlobalIsFinite); 4151 true, kGlobalIsFinite);
4141 4152
4142 // Install Global.isNaN 4153 // Install Global.isNaN
4143 SimpleInstallFunction(global_object, "isNaN", Builtins::kGlobalIsNaN, 1, true, 4154 SimpleInstallFunction(global_object, "isNaN", Builtins::kGlobalIsNaN, 1, true,
4144 kGlobalIsNaN); 4155 kGlobalIsNaN);
4145 4156
4146 // Install Array.prototype.concat 4157 // Install Array builtin functions.
4147 { 4158 {
4148 Handle<JSFunction> array_constructor(native_context()->array_function()); 4159 Handle<JSFunction> array_constructor(native_context()->array_function());
4149 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); 4160 Handle<JSArray> proto(JSArray::cast(array_constructor->prototype()));
4161
4162 // Verification of important array prototype properties.
4163 Object* length = proto->length();
4164 CHECK(length->IsSmi());
4165 CHECK(Smi::cast(length)->value() == 0);
4166 CHECK(proto->HasFastSmiOrObjectElements());
4167 // This is necessary to enable fast checks for absence of elements
4168 // on Array.prototype and below.
4169 proto->set_elements(heap()->empty_fixed_array());
4170
4171 // Install Array.prototype.concat
4150 Handle<JSFunction> concat = 4172 Handle<JSFunction> concat =
4151 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, 4173 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
4152 MaybeHandle<JSObject>(), Builtins::kArrayConcat); 4174 MaybeHandle<JSObject>(), Builtins::kArrayConcat);
4153 4175
4154 // Make sure that Array.prototype.concat appears to be compiled. 4176 // Make sure that Array.prototype.concat appears to be compiled.
4155 // The code will never be called, but inline caching for call will 4177 // The code will never be called, but inline caching for call will
4156 // only work if it appears to be compiled. 4178 // only work if it appears to be compiled.
4157 concat->shared()->DontAdaptArguments(); 4179 concat->shared()->DontAdaptArguments();
4158 DCHECK(concat->is_compiled()); 4180 DCHECK(concat->is_compiled());
4159 // Set the lengths for the functions to satisfy ECMA-262. 4181 // Set the lengths for the functions to satisfy ECMA-262.
4160 concat->shared()->set_length(1); 4182 concat->shared()->set_length(1);
4183
4184 // Install Array.prototype.forEach
4185 Handle<JSFunction> forEach = InstallArrayBuiltinFunction(
4186 proto, "forEach", Builtins::kArrayForEach, 2);
4187 // Add forEach to the context.
4188 native_context()->set_array_for_each_iterator(*forEach);
4189
4190 // Install Array.prototype.every
4191 InstallArrayBuiltinFunction(proto, "every", Builtins::kArrayEvery, 2);
4192
4193 // Install Array.prototype.some
4194 InstallArrayBuiltinFunction(proto, "some", Builtins::kArraySome, 2);
4195
4196 // Install Array.prototype.reduce
4197 InstallArrayBuiltinFunction(proto, "reduce", Builtins::kArrayReduce, 2);
4161 } 4198 }
4162 4199
4163 // Install InternalArray.prototype.concat 4200 // Install InternalArray.prototype.concat
4164 { 4201 {
4165 Handle<JSFunction> array_constructor( 4202 Handle<JSFunction> array_constructor(
4166 native_context()->internal_array_function()); 4203 native_context()->internal_array_function());
4167 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); 4204 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()));
4168 Handle<JSFunction> concat = 4205 Handle<JSFunction> concat =
4169 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, 4206 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
4170 MaybeHandle<JSObject>(), Builtins::kArrayConcat); 4207 MaybeHandle<JSObject>(), Builtins::kArrayConcat);
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
5057 } 5094 }
5058 5095
5059 5096
5060 // Called when the top-level V8 mutex is destroyed. 5097 // Called when the top-level V8 mutex is destroyed.
5061 void Bootstrapper::FreeThreadResources() { 5098 void Bootstrapper::FreeThreadResources() {
5062 DCHECK(!IsActive()); 5099 DCHECK(!IsActive());
5063 } 5100 }
5064 5101
5065 } // namespace internal 5102 } // namespace internal
5066 } // namespace v8 5103 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698