Commit 286747bb authored by Richard Stotz's avatar Richard Stotz Committed by V8 LUCI CQ

[wasm] Remove CallRefData

This CL removes the CallRefData data structure and accesses a funcref's
target and instance through the funcref.

Bug: v8:7748
Change-Id: Ic46b127f7775052d5df13b03c447e3b15328ad74
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3306486
Commit-Queue: Richard Stotz <rstz@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78194}
parent 574d4a8b
......@@ -488,20 +488,23 @@ macro GetTargetAndInstance(funcref: WasmInternalFunction): TargetAndInstance {
// Two slots per call_ref instruction. These slots' values can be:
// - uninitialized: (undefined, <unused>). Note: we use {undefined} as the
// sentinel as an optimization, as it's the default value for FixedArrays.
// - monomorphic: (funcref, call_ref_data)
// - monomorphic: (funcref, count (smi)). The second slot is a counter for how
// often the funcref in the first slot has been seen.
// - polymorphic: (fixed_array, <unused>). In this case, the array
// contains 2..4 pairs (funcref, call_ref_data) (like monomorphic data).
// contains 2..4 pairs (funcref, count (smi)) (like monomorphic data).
// - megamorphic: ("megamorphic" sentinel, <unused>)
//
// TODO(rstz): The counter might overflow if it exceeds the range of a Smi.
// This can lead to incorrect inlining decisions.
builtin CallRefIC(
vector: FixedArray, index: intptr,
funcref: WasmInternalFunction): TargetAndInstance {
const value = vector.objects[index];
if (value == funcref) {
// Monomorphic hit. Check for this case first to maximize its performance.
const data = UnsafeCast<CallRefData>(vector.objects[index + 1]);
data.count = data.count + 1;
return TargetAndInstance{target: data.target, instance: data.instance};
const count = UnsafeCast<Smi>(vector.objects[index + 1]) + SmiConstant(1);
vector.objects[index + 1] = count;
return GetTargetAndInstance(funcref);
}
// Check for polymorphic hit; its performance is second-most-important.
if (Is<FixedArray>(value)) {
......@@ -509,9 +512,9 @@ builtin CallRefIC(
for (let i: intptr = 0; i < entries.length_intptr; i += 2) {
if (entries.objects[i] == funcref) {
// Polymorphic hit.
const data = UnsafeCast<CallRefData>(entries.objects[i + 1]);
data.count = data.count + 1;
return TargetAndInstance{target: data.target, instance: data.instance};
const count = UnsafeCast<Smi>(entries.objects[i + 1]) + SmiConstant(1);
vector.objects[i + 1] = count;
return GetTargetAndInstance(funcref);
}
}
}
......@@ -519,10 +522,8 @@ builtin CallRefIC(
// instance. They all fall through to returning the computed data.
const result = GetTargetAndInstance(funcref);
if (TaggedEqual(value, Undefined)) {
const data = new
CallRefData{instance: result.instance, target: result.target, count: 1};
vector.objects[index] = funcref;
vector.objects[index + 1] = data;
vector.objects[index + 1] = SmiConstant(1);
} else if (Is<FixedArray>(value)) {
// Polymorphic miss.
const entries = UnsafeCast<FixedArray>(value);
......@@ -530,8 +531,6 @@ builtin CallRefIC(
vector.objects[index] = ic::kMegamorphicSymbol;
vector.objects[index + 1] = ic::kMegamorphicSymbol;
} else {
const data = new
CallRefData{instance: result.instance, target: result.target, count: 1};
const newEntries = UnsafeCast<FixedArray>(AllocateFixedArray(
ElementsKind::PACKED_ELEMENTS, entries.length_intptr + 2,
AllocationFlag::kNone));
......@@ -540,22 +539,20 @@ builtin CallRefIC(
}
const newIndex = entries.length_intptr;
newEntries.objects[newIndex] = funcref;
newEntries.objects[newIndex + 1] = data;
newEntries.objects[newIndex + 1] = SmiConstant(1);
vector.objects[index] = newEntries;
}
} else if (Is<WasmInternalFunction>(value)) {
// Monomorphic miss.
const data = new
CallRefData{instance: result.instance, target: result.target, count: 1};
const newEntries = UnsafeCast<FixedArray>(AllocateFixedArray(
ElementsKind::PACKED_ELEMENTS, 4, AllocationFlag::kNone));
newEntries.objects[0] = value;
newEntries.objects[1] = vector.objects[index + 1];
newEntries.objects[2] = funcref;
newEntries.objects[3] = data;
newEntries.objects[3] = SmiConstant(1);
vector.objects[index] = newEntries;
// Clear the old pointer to the first entry's data object; the specific
// value we write doesn't matter.
// Clear the first entry's counter; the specific value we write doesn't
// matter.
vector.objects[index + 1] = Undefined;
}
// The "ic::IsMegamorphic(value)" case doesn't need to do anything.
......
......@@ -1267,9 +1267,8 @@ std::vector<CallSiteFeedback> ProcessTypeFeedback(
PrintF("[Function #%d call_ref #%d inlineable (monomorphic)]\n",
func_index, i / 2);
}
CallRefData data = CallRefData::cast(feedback.get(i + 1));
result[i / 2] = {target.function_index(),
static_cast<int>(data.count())};
int32_t count = Smi::cast(feedback.get(i + 1)).value();
result[i / 2] = {target.function_index(), count};
continue;
}
} else if (value.IsFixedArray()) {
......@@ -1279,13 +1278,13 @@ std::vector<CallSiteFeedback> ProcessTypeFeedback(
FixedArray polymorphic = FixedArray::cast(value);
size_t total_count = 0;
for (int j = 0; j < polymorphic.length(); j += 2) {
total_count += CallRefData::cast(polymorphic.get(j + 1)).count();
total_count += Smi::cast(polymorphic.get(j + 1)).value();
}
int found_target = -1;
int found_count = -1;
double best_frequency = 0;
for (int j = 0; j < polymorphic.length(); j += 2) {
uint32_t this_count = CallRefData::cast(polymorphic.get(j + 1)).count();
int32_t this_count = Smi::cast(polymorphic.get(j + 1)).value();
double frequency = static_cast<double>(this_count) / total_count;
if (frequency > best_frequency) best_frequency = frequency;
if (frequency < 0.8) continue;
......
......@@ -194,10 +194,3 @@ extern class WasmArray extends WasmObject {
@if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
@ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}
@export
class CallRefData extends HeapObject {
instance: HeapObject;
target: RawPtr;
count: uint32;
}
......@@ -131,40 +131,39 @@ INSTANCE_TYPES = {
229: "UNCOMPILED_DATA_WITHOUT_PREPARSE_DATA_TYPE",
230: "WEAK_FIXED_ARRAY_TYPE",
231: "TRANSITION_ARRAY_TYPE",
232: "CALL_REF_DATA_TYPE",
233: "CELL_TYPE",
234: "CODE_TYPE",
235: "CODE_DATA_CONTAINER_TYPE",
236: "COVERAGE_INFO_TYPE",
237: "EMBEDDER_DATA_ARRAY_TYPE",
238: "FEEDBACK_METADATA_TYPE",
239: "FEEDBACK_VECTOR_TYPE",
240: "FILLER_TYPE",
241: "FREE_SPACE_TYPE",
242: "INTERNAL_CLASS_TYPE",
243: "INTERNAL_CLASS_WITH_STRUCT_ELEMENTS_TYPE",
244: "MAP_TYPE",
245: "MEGA_DOM_HANDLER_TYPE",
246: "ON_HEAP_BASIC_BLOCK_PROFILER_DATA_TYPE",
247: "PREPARSE_DATA_TYPE",
248: "PROPERTY_ARRAY_TYPE",
249: "PROPERTY_CELL_TYPE",
250: "SCOPE_INFO_TYPE",
251: "SHARED_FUNCTION_INFO_TYPE",
252: "SMI_BOX_TYPE",
253: "SMI_PAIR_TYPE",
254: "SORT_STATE_TYPE",
255: "SWISS_NAME_DICTIONARY_TYPE",
256: "WASM_API_FUNCTION_REF_TYPE",
257: "WEAK_ARRAY_LIST_TYPE",
258: "WEAK_CELL_TYPE",
259: "WASM_ARRAY_TYPE",
260: "WASM_STRUCT_TYPE",
261: "JS_PROXY_TYPE",
232: "CELL_TYPE",
233: "CODE_TYPE",
234: "CODE_DATA_CONTAINER_TYPE",
235: "COVERAGE_INFO_TYPE",
236: "EMBEDDER_DATA_ARRAY_TYPE",
237: "FEEDBACK_METADATA_TYPE",
238: "FEEDBACK_VECTOR_TYPE",
239: "FILLER_TYPE",
240: "FREE_SPACE_TYPE",
241: "INTERNAL_CLASS_TYPE",
242: "INTERNAL_CLASS_WITH_STRUCT_ELEMENTS_TYPE",
243: "MAP_TYPE",
244: "MEGA_DOM_HANDLER_TYPE",
245: "ON_HEAP_BASIC_BLOCK_PROFILER_DATA_TYPE",
246: "PREPARSE_DATA_TYPE",
247: "PROPERTY_ARRAY_TYPE",
248: "PROPERTY_CELL_TYPE",
249: "SCOPE_INFO_TYPE",
250: "SHARED_FUNCTION_INFO_TYPE",
251: "SMI_BOX_TYPE",
252: "SMI_PAIR_TYPE",
253: "SORT_STATE_TYPE",
254: "SWISS_NAME_DICTIONARY_TYPE",
255: "WASM_API_FUNCTION_REF_TYPE",
256: "WEAK_ARRAY_LIST_TYPE",
257: "WEAK_CELL_TYPE",
258: "WASM_ARRAY_TYPE",
259: "WASM_STRUCT_TYPE",
260: "JS_PROXY_TYPE",
1057: "JS_OBJECT_TYPE",
262: "JS_GLOBAL_OBJECT_TYPE",
263: "JS_GLOBAL_PROXY_TYPE",
264: "JS_MODULE_NAMESPACE_TYPE",
261: "JS_GLOBAL_OBJECT_TYPE",
262: "JS_GLOBAL_PROXY_TYPE",
263: "JS_MODULE_NAMESPACE_TYPE",
1040: "JS_SPECIAL_API_OBJECT_TYPE",
1041: "JS_PRIMITIVE_WRAPPER_TYPE",
1058: "JS_API_OBJECT_TYPE",
......@@ -259,16 +258,16 @@ INSTANCE_TYPES = {
# List of known V8 maps.
KNOWN_MAPS = {
("read_only_space", 0x02119): (244, "MetaMap"),
("read_only_space", 0x02119): (243, "MetaMap"),
("read_only_space", 0x02141): (131, "NullMap"),
("read_only_space", 0x02169): (225, "StrongDescriptorArrayMap"),
("read_only_space", 0x02191): (257, "WeakArrayListMap"),
("read_only_space", 0x02191): (256, "WeakArrayListMap"),
("read_only_space", 0x021d5): (156, "EnumCacheMap"),
("read_only_space", 0x02209): (176, "FixedArrayMap"),
("read_only_space", 0x02255): (8, "OneByteInternalizedStringMap"),
("read_only_space", 0x022a1): (241, "FreeSpaceMap"),
("read_only_space", 0x022c9): (240, "OnePointerFillerMap"),
("read_only_space", 0x022f1): (240, "TwoPointerFillerMap"),
("read_only_space", 0x022a1): (240, "FreeSpaceMap"),
("read_only_space", 0x022c9): (239, "OnePointerFillerMap"),
("read_only_space", 0x022f1): (239, "TwoPointerFillerMap"),
("read_only_space", 0x02319): (131, "UninitializedMap"),
("read_only_space", 0x02391): (131, "UndefinedMap"),
("read_only_space", 0x023d5): (130, "HeapNumberMap"),
......@@ -279,15 +278,15 @@ KNOWN_MAPS = {
("read_only_space", 0x0255d): (177, "HashTableMap"),
("read_only_space", 0x02585): (128, "SymbolMap"),
("read_only_space", 0x025ad): (40, "OneByteStringMap"),
("read_only_space", 0x025d5): (250, "ScopeInfoMap"),
("read_only_space", 0x025fd): (251, "SharedFunctionInfoMap"),
("read_only_space", 0x02625): (234, "CodeMap"),
("read_only_space", 0x0264d): (233, "CellMap"),
("read_only_space", 0x02675): (249, "GlobalPropertyCellMap"),
("read_only_space", 0x025d5): (249, "ScopeInfoMap"),
("read_only_space", 0x025fd): (250, "SharedFunctionInfoMap"),
("read_only_space", 0x02625): (233, "CodeMap"),
("read_only_space", 0x0264d): (232, "CellMap"),
("read_only_space", 0x02675): (248, "GlobalPropertyCellMap"),
("read_only_space", 0x0269d): (204, "ForeignMap"),
("read_only_space", 0x026c5): (231, "TransitionArrayMap"),
("read_only_space", 0x026ed): (45, "ThinOneByteStringMap"),
("read_only_space", 0x02715): (239, "FeedbackVectorMap"),
("read_only_space", 0x02715): (238, "FeedbackVectorMap"),
("read_only_space", 0x0274d): (131, "ArgumentsMarkerMap"),
("read_only_space", 0x027ad): (131, "ExceptionMap"),
("read_only_space", 0x02809): (131, "TerminationExceptionMap"),
......@@ -295,17 +294,17 @@ KNOWN_MAPS = {
("read_only_space", 0x028d1): (131, "StaleRegisterMap"),
("read_only_space", 0x02931): (188, "ScriptContextTableMap"),
("read_only_space", 0x02959): (186, "ClosureFeedbackCellArrayMap"),
("read_only_space", 0x02981): (238, "FeedbackMetadataArrayMap"),
("read_only_space", 0x02981): (237, "FeedbackMetadataArrayMap"),
("read_only_space", 0x029a9): (176, "ArrayListMap"),
("read_only_space", 0x029d1): (129, "BigIntMap"),
("read_only_space", 0x029f9): (187, "ObjectBoilerplateDescriptionMap"),
("read_only_space", 0x02a21): (190, "BytecodeArrayMap"),
("read_only_space", 0x02a49): (235, "CodeDataContainerMap"),
("read_only_space", 0x02a71): (236, "CoverageInfoMap"),
("read_only_space", 0x02a49): (234, "CodeDataContainerMap"),
("read_only_space", 0x02a71): (235, "CoverageInfoMap"),
("read_only_space", 0x02a99): (191, "FixedDoubleArrayMap"),
("read_only_space", 0x02ac1): (179, "GlobalDictionaryMap"),
("read_only_space", 0x02ae9): (157, "ManyClosuresCellMap"),
("read_only_space", 0x02b11): (245, "MegaDomHandlerMap"),
("read_only_space", 0x02b11): (244, "MegaDomHandlerMap"),
("read_only_space", 0x02b39): (176, "ModuleInfoMap"),
("read_only_space", 0x02b61): (180, "NameDictionaryMap"),
("read_only_space", 0x02b89): (157, "NoClosuresCellMap"),
......@@ -314,8 +313,8 @@ KNOWN_MAPS = {
("read_only_space", 0x02c01): (182, "OrderedHashMapMap"),
("read_only_space", 0x02c29): (183, "OrderedHashSetMap"),
("read_only_space", 0x02c51): (184, "OrderedNameDictionaryMap"),
("read_only_space", 0x02c79): (247, "PreparseDataMap"),
("read_only_space", 0x02ca1): (248, "PropertyArrayMap"),
("read_only_space", 0x02c79): (246, "PreparseDataMap"),
("read_only_space", 0x02ca1): (247, "PropertyArrayMap"),
("read_only_space", 0x02cc9): (153, "SideEffectCallHandlerInfoMap"),
("read_only_space", 0x02cf1): (153, "SideEffectFreeCallHandlerInfoMap"),
("read_only_space", 0x02d19): (153, "NextCallSideEffectFreeCallHandlerInfoMap"),
......@@ -324,9 +323,9 @@ KNOWN_MAPS = {
("read_only_space", 0x02d91): (220, "SmallOrderedHashSetMap"),
("read_only_space", 0x02db9): (221, "SmallOrderedNameDictionaryMap"),
("read_only_space", 0x02de1): (226, "SourceTextModuleMap"),
("read_only_space", 0x02e09): (255, "SwissNameDictionaryMap"),
("read_only_space", 0x02e09): (254, "SwissNameDictionaryMap"),
("read_only_space", 0x02e31): (227, "SyntheticModuleMap"),
("read_only_space", 0x02e59): (256, "WasmApiFunctionRefMap"),
("read_only_space", 0x02e59): (255, "WasmApiFunctionRefMap"),
("read_only_space", 0x02e81): (213, "WasmCapiFunctionDataMap"),
("read_only_space", 0x02ea9): (214, "WasmExportedFunctionDataMap"),
("read_only_space", 0x02ed1): (205, "WasmInternalFunctionMap"),
......@@ -334,8 +333,8 @@ KNOWN_MAPS = {
("read_only_space", 0x02f21): (206, "WasmTypeInfoMap"),
("read_only_space", 0x02f49): (230, "WeakFixedArrayMap"),
("read_only_space", 0x02f71): (178, "EphemeronHashTableMap"),
("read_only_space", 0x02f99): (237, "EmbedderDataArrayMap"),
("read_only_space", 0x02fc1): (258, "WeakCellMap"),
("read_only_space", 0x02f99): (236, "EmbedderDataArrayMap"),
("read_only_space", 0x02fc1): (257, "WeakCellMap"),
("read_only_space", 0x02fe9): (32, "StringMap"),
("read_only_space", 0x03011): (41, "ConsOneByteStringMap"),
("read_only_space", 0x03039): (33, "ConsStringMap"),
......@@ -397,33 +396,32 @@ KNOWN_MAPS = {
("read_only_space", 0x06239): (224, "DescriptorArrayMap"),
("read_only_space", 0x06261): (229, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x06289): (228, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x062b1): (246, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x062b1): (245, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x062d9): (207, "TurbofanBitsetTypeMap"),
("read_only_space", 0x06301): (211, "TurbofanUnionTypeMap"),
("read_only_space", 0x06329): (210, "TurbofanRangeTypeMap"),
("read_only_space", 0x06351): (208, "TurbofanHeapConstantTypeMap"),
("read_only_space", 0x06379): (209, "TurbofanOtherNumberConstantTypeMap"),
("read_only_space", 0x063a1): (242, "InternalClassMap"),
("read_only_space", 0x063c9): (253, "SmiPairMap"),
("read_only_space", 0x063f1): (252, "SmiBoxMap"),
("read_only_space", 0x063a1): (241, "InternalClassMap"),
("read_only_space", 0x063c9): (252, "SmiPairMap"),
("read_only_space", 0x063f1): (251, "SmiBoxMap"),
("read_only_space", 0x06419): (216, "ExportedSubClassBaseMap"),
("read_only_space", 0x06441): (217, "ExportedSubClassMap"),
("read_only_space", 0x06469): (222, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x06491): (223, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x064b9): (192, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x064e1): (243, "InternalClassWithStructElementsMap"),
("read_only_space", 0x064e1): (242, "InternalClassWithStructElementsMap"),
("read_only_space", 0x06509): (218, "ExportedSubClass2Map"),
("read_only_space", 0x06531): (254, "SortStateMap"),
("read_only_space", 0x06559): (232, "CallRefDataMap"),
("read_only_space", 0x06581): (146, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x065a9): (146, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x065d1): (137, "LoadHandler1Map"),
("read_only_space", 0x065f9): (137, "LoadHandler2Map"),
("read_only_space", 0x06621): (137, "LoadHandler3Map"),
("read_only_space", 0x06649): (138, "StoreHandler0Map"),
("read_only_space", 0x06671): (138, "StoreHandler1Map"),
("read_only_space", 0x06699): (138, "StoreHandler2Map"),
("read_only_space", 0x066c1): (138, "StoreHandler3Map"),
("read_only_space", 0x06531): (253, "SortStateMap"),
("read_only_space", 0x06559): (146, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x06581): (146, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x065a9): (137, "LoadHandler1Map"),
("read_only_space", 0x065d1): (137, "LoadHandler2Map"),
("read_only_space", 0x065f9): (137, "LoadHandler3Map"),
("read_only_space", 0x06621): (138, "StoreHandler0Map"),
("read_only_space", 0x06649): (138, "StoreHandler1Map"),
("read_only_space", 0x06671): (138, "StoreHandler2Map"),
("read_only_space", 0x06699): (138, "StoreHandler3Map"),
("map_space", 0x02119): (1057, "ExternalMap"),
("map_space", 0x02141): (2114, "JSMessageObjectMap"),
}
......
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