Commit 519d3949 authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[rab/gsab] Simplify JSFunction::GetDerivedRabGsabMap

Bug: v8:11111
Change-Id: I0bea83be43f9749b95caed146224d21b5128a478
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2904207
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74665}
parent bc11dbcb
...@@ -62,6 +62,30 @@ enum ContextLookupFlags { ...@@ -62,6 +62,30 @@ enum ContextLookupFlags {
V(CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX, HeapObject, \ V(CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX, HeapObject, \
continuation_preserved_embedder_data) \ continuation_preserved_embedder_data) \
NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \
/* TypedArray constructors - these must stay in order! */ \
V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \
V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \
V(INT16_ARRAY_FUN_INDEX, JSFunction, int16_array_fun) \
V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \
V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \
V(FLOAT32_ARRAY_FUN_INDEX, JSFunction, float32_array_fun) \
V(FLOAT64_ARRAY_FUN_INDEX, JSFunction, float64_array_fun) \
V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \
V(BIGUINT64_ARRAY_FUN_INDEX, JSFunction, biguint64_array_fun) \
V(BIGINT64_ARRAY_FUN_INDEX, JSFunction, bigint64_array_fun) \
V(RAB_GSAB_UINT8_ARRAY_MAP_INDEX, Map, rab_gsab_uint8_array_map) \
V(RAB_GSAB_INT8_ARRAY_MAP_INDEX, Map, rab_gsab_int8_array_map) \
V(RAB_GSAB_UINT16_ARRAY_MAP_INDEX, Map, rab_gsab_uint16_array_map) \
V(RAB_GSAB_INT16_ARRAY_MAP_INDEX, Map, rab_gsab_int16_array_map) \
V(RAB_GSAB_UINT32_ARRAY_MAP_INDEX, Map, rab_gsab_uint32_array_map) \
V(RAB_GSAB_INT32_ARRAY_MAP_INDEX, Map, rab_gsab_int32_array_map) \
V(RAB_GSAB_FLOAT32_ARRAY_MAP_INDEX, Map, rab_gsab_float32_array_map) \
V(RAB_GSAB_FLOAT64_ARRAY_MAP_INDEX, Map, rab_gsab_float64_array_map) \
V(RAB_GSAB_UINT8_CLAMPED_ARRAY_MAP_INDEX, Map, \
rab_gsab_uint8_clamped_array_map) \
V(RAB_GSAB_BIGUINT64_ARRAY_MAP_INDEX, Map, rab_gsab_biguint64_array_map) \
V(RAB_GSAB_BIGINT64_ARRAY_MAP_INDEX, Map, rab_gsab_bigint64_array_map) \
/* Below is alpha-sorted */ \ /* Below is alpha-sorted */ \
V(ACCESSOR_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, \ V(ACCESSOR_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, \
accessor_property_descriptor_map) \ accessor_property_descriptor_map) \
...@@ -78,8 +102,6 @@ enum ContextLookupFlags { ...@@ -78,8 +102,6 @@ enum ContextLookupFlags {
async_generator_function_function) \ async_generator_function_function) \
V(ATOMICS_OBJECT, JSObject, atomics_object) \ V(ATOMICS_OBJECT, JSObject, atomics_object) \
V(BIGINT_FUNCTION_INDEX, JSFunction, bigint_function) \ V(BIGINT_FUNCTION_INDEX, JSFunction, bigint_function) \
V(BIGINT64_ARRAY_FUN_INDEX, JSFunction, bigint64_array_fun) \
V(BIGUINT64_ARRAY_FUN_INDEX, JSFunction, biguint64_array_fun) \
V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \ V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \
V(BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX, Map, \ V(BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX, Map, \
bound_function_with_constructor_map) \ bound_function_with_constructor_map) \
...@@ -104,8 +126,6 @@ enum ContextLookupFlags { ...@@ -104,8 +126,6 @@ enum ContextLookupFlags {
V(FAST_ALIASED_ARGUMENTS_MAP_INDEX, Map, fast_aliased_arguments_map) \ V(FAST_ALIASED_ARGUMENTS_MAP_INDEX, Map, fast_aliased_arguments_map) \
V(FAST_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, FixedArray, \ V(FAST_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, FixedArray, \
fast_template_instantiations_cache) \ fast_template_instantiations_cache) \
V(FLOAT32_ARRAY_FUN_INDEX, JSFunction, float32_array_fun) \
V(FLOAT64_ARRAY_FUN_INDEX, JSFunction, float64_array_fun) \
V(FUNCTION_FUNCTION_INDEX, JSFunction, function_function) \ V(FUNCTION_FUNCTION_INDEX, JSFunction, function_function) \
V(GENERATOR_FUNCTION_FUNCTION_INDEX, JSFunction, \ V(GENERATOR_FUNCTION_FUNCTION_INDEX, JSFunction, \
generator_function_function) \ generator_function_function) \
...@@ -139,9 +159,6 @@ enum ContextLookupFlags { ...@@ -139,9 +159,6 @@ enum ContextLookupFlags {
V(INITIAL_STRING_PROTOTYPE_INDEX, JSObject, initial_string_prototype) \ V(INITIAL_STRING_PROTOTYPE_INDEX, JSObject, initial_string_prototype) \
V(INITIAL_WEAKMAP_PROTOTYPE_MAP_INDEX, Map, initial_weakmap_prototype_map) \ V(INITIAL_WEAKMAP_PROTOTYPE_MAP_INDEX, Map, initial_weakmap_prototype_map) \
V(INITIAL_WEAKSET_PROTOTYPE_MAP_INDEX, Map, initial_weakset_prototype_map) \ V(INITIAL_WEAKSET_PROTOTYPE_MAP_INDEX, Map, initial_weakset_prototype_map) \
V(INT16_ARRAY_FUN_INDEX, JSFunction, int16_array_fun) \
V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \
V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \
V(INTL_COLLATOR_FUNCTION_INDEX, JSFunction, intl_collator_function) \ V(INTL_COLLATOR_FUNCTION_INDEX, JSFunction, intl_collator_function) \
V(INTL_DATE_TIME_FORMAT_FUNCTION_INDEX, JSFunction, \ V(INTL_DATE_TIME_FORMAT_FUNCTION_INDEX, JSFunction, \
intl_date_time_format_function) \ intl_date_time_format_function) \
...@@ -212,18 +229,6 @@ enum ContextLookupFlags { ...@@ -212,18 +229,6 @@ enum ContextLookupFlags {
V(PROXY_MAP_INDEX, Map, proxy_map) \ V(PROXY_MAP_INDEX, Map, proxy_map) \
V(PROXY_REVOCABLE_RESULT_MAP_INDEX, Map, proxy_revocable_result_map) \ V(PROXY_REVOCABLE_RESULT_MAP_INDEX, Map, proxy_revocable_result_map) \
V(PROMISE_PROTOTYPE_INDEX, JSObject, promise_prototype) \ V(PROMISE_PROTOTYPE_INDEX, JSObject, promise_prototype) \
V(RAB_GSAB_UINT8_ARRAY_MAP_INDEX, Map, rab_gsab_uint8_array_map) \
V(RAB_GSAB_INT8_ARRAY_MAP_INDEX, Map, rab_gsab_int8_array_map) \
V(RAB_GSAB_UINT16_ARRAY_MAP_INDEX, Map, rab_gsab_uint16_array_map) \
V(RAB_GSAB_INT16_ARRAY_MAP_INDEX, Map, rab_gsab_int16_array_map) \
V(RAB_GSAB_UINT32_ARRAY_MAP_INDEX, Map, rab_gsab_uint32_array_map) \
V(RAB_GSAB_INT32_ARRAY_MAP_INDEX, Map, rab_gsab_int32_array_map) \
V(RAB_GSAB_FLOAT32_ARRAY_MAP_INDEX, Map, rab_gsab_float32_array_map) \
V(RAB_GSAB_FLOAT64_ARRAY_MAP_INDEX, Map, rab_gsab_float64_array_map) \
V(RAB_GSAB_UINT8_CLAMPED_ARRAY_MAP_INDEX, Map, \
rab_gsab_uint8_clamped_array_map) \
V(RAB_GSAB_BIGUINT64_ARRAY_MAP_INDEX, Map, rab_gsab_biguint64_array_map) \
V(RAB_GSAB_BIGINT64_ARRAY_MAP_INDEX, Map, rab_gsab_bigint64_array_map) \
V(RECORDER_CONTEXT_ID, Object, recorder_context_id) \ V(RECORDER_CONTEXT_ID, Object, recorder_context_id) \
V(REGEXP_EXEC_FUNCTION_INDEX, JSFunction, regexp_exec_function) \ V(REGEXP_EXEC_FUNCTION_INDEX, JSFunction, regexp_exec_function) \
V(REGEXP_FUNCTION_INDEX, JSFunction, regexp_function) \ V(REGEXP_FUNCTION_INDEX, JSFunction, regexp_function) \
...@@ -298,10 +303,6 @@ enum ContextLookupFlags { ...@@ -298,10 +303,6 @@ enum ContextLookupFlags {
V(TEMPLATE_WEAKMAP_INDEX, HeapObject, template_weakmap) \ V(TEMPLATE_WEAKMAP_INDEX, HeapObject, template_weakmap) \
V(TYPED_ARRAY_FUN_INDEX, JSFunction, typed_array_function) \ V(TYPED_ARRAY_FUN_INDEX, JSFunction, typed_array_function) \
V(TYPED_ARRAY_PROTOTYPE_INDEX, JSObject, typed_array_prototype) \ V(TYPED_ARRAY_PROTOTYPE_INDEX, JSObject, typed_array_prototype) \
V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \
V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \
V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \
V(ARRAY_ENTRIES_ITERATOR_INDEX, JSFunction, array_entries_iterator) \ V(ARRAY_ENTRIES_ITERATOR_INDEX, JSFunction, array_entries_iterator) \
V(ARRAY_FOR_EACH_ITERATOR_INDEX, JSFunction, array_for_each_iterator) \ V(ARRAY_FOR_EACH_ITERATOR_INDEX, JSFunction, array_for_each_iterator) \
V(ARRAY_KEYS_ITERATOR_INDEX, JSFunction, array_keys_iterator) \ V(ARRAY_KEYS_ITERATOR_INDEX, JSFunction, array_keys_iterator) \
...@@ -540,6 +541,10 @@ class Context : public TorqueGeneratedContext<Context, HeapObject> { ...@@ -540,6 +541,10 @@ class Context : public TorqueGeneratedContext<Context, HeapObject> {
static const int FIRST_FUNCTION_MAP_INDEX = SLOPPY_FUNCTION_MAP_INDEX; static const int FIRST_FUNCTION_MAP_INDEX = SLOPPY_FUNCTION_MAP_INDEX;
static const int LAST_FUNCTION_MAP_INDEX = CLASS_FUNCTION_MAP_INDEX; static const int LAST_FUNCTION_MAP_INDEX = CLASS_FUNCTION_MAP_INDEX;
static const int FIRST_FIXED_TYPED_ARRAY_FUN_INDEX = UINT8_ARRAY_FUN_INDEX;
static const int FIRST_RAB_GSAB_TYPED_ARRAY_MAP_INDEX =
RAB_GSAB_UINT8_ARRAY_MAP_INDEX;
static const int kNoContext = 0; static const int kNoContext = 0;
static const int kInvalidContext = 1; static const int kInvalidContext = 1;
......
...@@ -796,49 +796,55 @@ MaybeHandle<Map> JSFunction::GetDerivedMap(Isolate* isolate, ...@@ -796,49 +796,55 @@ MaybeHandle<Map> JSFunction::GetDerivedMap(Isolate* isolate,
return map; return map;
} }
namespace {
// Assert that the computations in TypedArrayElementsKindToConstructorIndex and
// TypedArrayElementsKindToRabGsabCtorIndex are sound.
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) \
STATIC_ASSERT(Context::TYPE##_ARRAY_FUN_INDEX == \
Context::FIRST_FIXED_TYPED_ARRAY_FUN_INDEX + \
ElementsKind::TYPE##_ELEMENTS - \
ElementsKind::FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND); \
STATIC_ASSERT(Context::RAB_GSAB_##TYPE##_ARRAY_MAP_INDEX == \
Context::FIRST_RAB_GSAB_TYPED_ARRAY_MAP_INDEX + \
ElementsKind::TYPE##_ELEMENTS - \
ElementsKind::FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND);
TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
int TypedArrayElementsKindToConstructorIndex(ElementsKind elements_kind) {
return Context::FIRST_FIXED_TYPED_ARRAY_FUN_INDEX + elements_kind -
ElementsKind::FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND;
}
int TypedArrayElementsKindToRabGsabCtorIndex(ElementsKind elements_kind) {
return Context::FIRST_RAB_GSAB_TYPED_ARRAY_MAP_INDEX + elements_kind -
ElementsKind::FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND;
}
} // namespace
Handle<Map> JSFunction::GetDerivedRabGsabMap(Isolate* isolate, Handle<Map> JSFunction::GetDerivedRabGsabMap(Isolate* isolate,
Handle<JSFunction> constructor, Handle<JSFunction> constructor,
Handle<JSReceiver> new_target) { Handle<JSReceiver> new_target) {
Handle<Map> map =
GetDerivedMap(isolate, constructor, new_target).ToHandleChecked();
{ {
DisallowHeapAllocation no_alloc; DisallowHeapAllocation no_alloc;
NativeContext context = isolate->context().native_context(); NativeContext context = isolate->context().native_context();
if (*new_target == context.uint8_array_fun()) { int ctor_index =
return handle(context.rab_gsab_uint8_array_map(), isolate); TypedArrayElementsKindToConstructorIndex(map->elements_kind());
} if (*new_target == context.get(ctor_index)) {
if (*new_target == context.int8_array_fun()) { ctor_index =
return handle(context.rab_gsab_int8_array_map(), isolate); TypedArrayElementsKindToRabGsabCtorIndex(map->elements_kind());
} return handle(Map::cast(context.get(ctor_index)), isolate);
if (*new_target == context.uint16_array_fun()) {
return handle(context.rab_gsab_uint16_array_map(), isolate);
}
if (*new_target == context.int16_array_fun()) {
return handle(context.rab_gsab_int16_array_map(), isolate);
}
if (*new_target == context.uint32_array_fun()) {
return handle(context.rab_gsab_uint32_array_map(), isolate);
}
if (*new_target == context.int32_array_fun()) {
return handle(context.rab_gsab_int32_array_map(), isolate);
}
if (*new_target == context.float32_array_fun()) {
return handle(context.rab_gsab_float32_array_map(), isolate);
}
if (*new_target == context.float64_array_fun()) {
return handle(context.rab_gsab_float64_array_map(), isolate);
}
if (*new_target == context.biguint64_array_fun()) {
return handle(context.rab_gsab_biguint64_array_map(), isolate);
}
if (*new_target == context.bigint64_array_fun()) {
return handle(context.rab_gsab_bigint64_array_map(), isolate);
} }
} }
// This only happens when subclassing TypedArrays. Create a new map with the // This only happens when subclassing TypedArrays. Create a new map with the
// corresponding RAB / GSAB ElementsKind. Note: the map is not cached and // corresponding RAB / GSAB ElementsKind. Note: the map is not cached and
// reused -> every array gets a unique map, making ICs slow. // reused -> every array gets a unique map, making ICs slow.
Handle<Map> map =
GetDerivedMap(isolate, constructor, new_target).ToHandleChecked();
Handle<Map> rab_gsab_map = Map::Copy(isolate, map, "RAB / GSAB"); Handle<Map> rab_gsab_map = Map::Copy(isolate, map, "RAB / GSAB");
rab_gsab_map->set_elements_kind( rab_gsab_map->set_elements_kind(
GetCorrespondingRabGsabElementsKind(map->elements_kind())); GetCorrespondingRabGsabElementsKind(map->elements_kind()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment