[Intl] Remove bound function SFIs from context

Instead of creating the SFIs during bootstrapping and storing on the
context, this patch just creates the SFIs on demand.

This patch saves 8 words per context, and several words per bound
function by not storing the SFI.

The created bound JSFunction is cached on the instance anyway, so it's
totally fine to take a small hit when creating the bound JSFunction.

Previously in the JS implementation, the creation of a bound function
was even slower as it was a lazy function that would have to parsed,
compiled and executed. So this is a step up in terms up perf and
memory.

Bug: v8:5751
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: If3b8461d00e5b37567b34b236d44e14576b630ff
Reviewed-on: https://chromium-review.googlesource.com/1200006
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55566}
This commit is contained in:
Sathya Gunasekaran 2018-08-31 14:10:17 -07:00 committed by Commit Bot
parent 81fb59c638
commit e56bf9f45e
3 changed files with 24 additions and 103 deletions

View File

@ -2926,13 +2926,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("format"),
Builtins::kDateTimeFormatPrototypeFormat, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kDateTimeFormatInternalFormat,
factory->empty_string(), 1);
native_context()->set_date_format_internal_format_shared_fun(*info);
}
}
{
@ -2961,14 +2954,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("format"),
Builtins::kNumberFormatPrototypeFormatNumber, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kNumberFormatInternalFormatNumber,
factory->empty_string(), 1);
native_context()->set_number_format_internal_format_number_shared_fun(
*info);
}
}
{
@ -2995,13 +2980,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("compare"),
Builtins::kCollatorPrototypeCompare, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kCollatorInternalCompare,
factory->empty_string(), 2);
native_context()->set_collator_internal_compare_shared_fun(*info);
}
}
{
@ -3029,58 +3007,21 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory->InternalizeUtf8String("adoptText"),
Builtins::kBreakIteratorPrototypeAdoptText, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalAdoptText,
factory->empty_string(), 1);
native_context()->set_break_iterator_internal_adopt_text_shared_fun(
*info);
}
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("first"),
Builtins::kBreakIteratorPrototypeFirst, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalFirst,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_first_shared_fun(*info);
}
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("next"),
Builtins::kBreakIteratorPrototypeNext, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalNext,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_next_shared_fun(*info);
}
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("current"),
Builtins::kBreakIteratorPrototypeCurrent, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalCurrent,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_current_shared_fun(*info);
}
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("breakType"),
Builtins::kBreakIteratorPrototypeBreakType, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalBreakType,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_break_type_shared_fun(
*info);
}
}
{

View File

@ -547,11 +547,7 @@ BUILTIN(DateTimeFormatPrototypeFormatToParts) {
namespace {
Handle<JSFunction> CreateBoundFunction(Isolate* isolate,
Handle<JSObject> object,
int shared_function_info_context_slot) {
// Check if 'shared_info_context_slot' is a valid slot.
DCHECK_GT(shared_function_info_context_slot, Context::NATIVE_CONTEXT_INDEX);
DCHECK_LT(shared_function_info_context_slot, Context::NATIVE_CONTEXT_SLOTS);
Builtins::Name builtin_id, int len) {
Handle<NativeContext> native_context(isolate->context()->native_context(),
isolate);
Handle<Context> context = isolate->factory()->NewBuiltinContext(
@ -561,9 +557,12 @@ Handle<JSFunction> CreateBoundFunction(Isolate* isolate,
context->set(static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction),
*object);
Handle<SharedFunctionInfo> info(SharedFunctionInfo::cast(native_context->get(
shared_function_info_context_slot)),
isolate);
Handle<SharedFunctionInfo> info =
isolate->factory()->NewSharedFunctionInfoForBuiltin(
isolate->factory()->empty_string(), builtin_id, kNormalFunction);
info->set_internal_formal_parameter_count(len);
info->set_length(len);
Handle<Map> map = isolate->strict_function_without_prototype_map();
Handle<JSFunction> new_bound_function =
@ -600,9 +599,9 @@ BUILTIN(NumberFormatPrototypeFormatNumber) {
return *bound_format;
}
Handle<JSFunction> new_bound_format_function = CreateBoundFunction(
isolate, number_format_holder,
Context::INTL_NUMBER_FORMAT_INTERNAL_FORMAT_NUMBER_SHARED_FUN);
Handle<JSFunction> new_bound_format_function =
CreateBoundFunction(isolate, number_format_holder,
Builtins::kNumberFormatInternalFormatNumber, 1);
// 4. c. Set nf.[[BoundFormat]] to F.
number_format_holder->SetEmbedderField(NumberFormat::kBoundFormatIndex,
@ -674,9 +673,8 @@ BUILTIN(DateTimeFormatPrototypeFormat) {
return *bound_format;
}
Handle<JSFunction> new_bound_format_function =
CreateBoundFunction(isolate, date_format_holder,
Context::INTL_DATE_FORMAT_INTERNAL_FORMAT_SHARED_FUN);
Handle<JSFunction> new_bound_format_function = CreateBoundFunction(
isolate, date_format_holder, Builtins::kDateTimeFormatInternalFormat, 1);
// 4.c. Set dtf.[[BoundFormat]] to F.
date_format_holder->SetEmbedderField(DateFormat::kBoundFormatIndex,
@ -1101,7 +1099,7 @@ BUILTIN(CollatorPrototypeCompare) {
}
Handle<JSFunction> new_bound_compare_function = CreateBoundFunction(
isolate, collator, Context::INTL_COLLATOR_INTERNAL_COMPARE_SHARED_FUN);
isolate, collator, Builtins::kCollatorInternalCompare, 2);
// 4.c. Set collator.[[BoundCompare]] to F.
collator->set_bound_compare(*new_bound_compare_function);
@ -1164,9 +1162,9 @@ BUILTIN(BreakIteratorPrototypeAdoptText) {
return *bound_adopt_text;
}
Handle<JSFunction> new_bound_adopt_text_function = CreateBoundFunction(
isolate, break_iterator_holder,
Context::INTL_V8_BREAK_ITERATOR_INTERNAL_ADOPT_TEXT_SHARED_FUN);
Handle<JSFunction> new_bound_adopt_text_function =
CreateBoundFunction(isolate, break_iterator_holder,
Builtins::kBreakIteratorInternalAdoptText, 1);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundAdoptTextIndex,
*new_bound_adopt_text_function);
@ -1220,8 +1218,7 @@ BUILTIN(BreakIteratorPrototypeFirst) {
}
Handle<JSFunction> new_bound_first_function = CreateBoundFunction(
isolate, break_iterator_holder,
Context::INTL_V8_BREAK_ITERATOR_INTERNAL_FIRST_SHARED_FUN);
isolate, break_iterator_holder, Builtins::kBreakIteratorInternalFirst, 0);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundFirstIndex,
*new_bound_first_function);
@ -1272,8 +1269,7 @@ BUILTIN(BreakIteratorPrototypeNext) {
}
Handle<JSFunction> new_bound_next_function = CreateBoundFunction(
isolate, break_iterator_holder,
Context::INTL_V8_BREAK_ITERATOR_INTERNAL_NEXT_SHARED_FUN);
isolate, break_iterator_holder, Builtins::kBreakIteratorInternalNext, 0);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundNextIndex,
*new_bound_next_function);
@ -1324,9 +1320,9 @@ BUILTIN(BreakIteratorPrototypeCurrent) {
return *bound_current;
}
Handle<JSFunction> new_bound_current_function = CreateBoundFunction(
isolate, break_iterator_holder,
Context::INTL_V8_BREAK_ITERATOR_INTERNAL_CURRENT_SHARED_FUN);
Handle<JSFunction> new_bound_current_function =
CreateBoundFunction(isolate, break_iterator_holder,
Builtins::kBreakIteratorInternalCurrent, 0);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundCurrentIndex,
*new_bound_current_function);
@ -1377,9 +1373,9 @@ BUILTIN(BreakIteratorPrototypeBreakType) {
return *bound_break_type;
}
Handle<JSFunction> new_bound_break_type_function = CreateBoundFunction(
isolate, break_iterator_holder,
Context::INTL_V8_BREAK_ITERATOR_INTERNAL_BREAK_TYPE_SHARED_FUN);
Handle<JSFunction> new_bound_break_type_function =
CreateBoundFunction(isolate, break_iterator_holder,
Builtins::kBreakIteratorInternalBreakType, 0);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundBreakTypeIndex,
*new_bound_break_type_function);

View File

@ -204,29 +204,13 @@ enum ContextLookupFlags {
V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \
V(INTL_DATE_TIME_FORMAT_FUNCTION_INDEX, JSFunction, \
intl_date_time_format_function) \
V(INTL_DATE_FORMAT_INTERNAL_FORMAT_SHARED_FUN, SharedFunctionInfo, \
date_format_internal_format_shared_fun) \
V(INTL_NUMBER_FORMAT_FUNCTION_INDEX, JSFunction, \
intl_number_format_function) \
V(INTL_NUMBER_FORMAT_INTERNAL_FORMAT_NUMBER_SHARED_FUN, SharedFunctionInfo, \
number_format_internal_format_number_shared_fun) \
V(INTL_LOCALE_FUNCTION_INDEX, JSFunction, intl_locale_function) \
V(INTL_COLLATOR_FUNCTION_INDEX, JSFunction, intl_collator_function) \
V(INTL_COLLATOR_INTERNAL_COMPARE_SHARED_FUN, SharedFunctionInfo, \
collator_internal_compare_shared_fun) \
V(INTL_PLURAL_RULES_FUNCTION_INDEX, JSFunction, intl_plural_rules_function) \
V(INTL_V8_BREAK_ITERATOR_FUNCTION_INDEX, JSFunction, \
intl_v8_break_iterator_function) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_ADOPT_TEXT_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_adopt_text_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_FIRST_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_first_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_NEXT_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_next_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_CURRENT_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_current_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_BREAK_TYPE_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_break_type_shared_fun) \
V(JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX, Map, \
js_array_packed_smi_elements_map) \
V(JS_ARRAY_HOLEY_SMI_ELEMENTS_MAP_INDEX, Map, \