Skip to content

Commit d6ae50f

Browse files
rayw000targos
authored andcommittedNov 21, 2021
deps: V8: cherry-pick 7ae0b77628f6
Original commit message: [interpreter] Stop jump-table optimizing switch stms when spread overflows Bug: v8:12389 Change-Id: I53c728ab0c8ba38c7dd96c7e1089f771ba44b9f0 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3289227 Reviewed-by: Leszek Swirski <[email protected]> Commit-Queue: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/heads/main@{#77995} Refs: v8/v8@7ae0b77 PR-URL: #40882 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e60053d commit d6ae50f

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
 

‎common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.10',
39+
'v8_embedder_string': '-node.11',
4040

4141
##### V8 defaults for Node.js #####
4242

‎deps/v8/src/interpreter/bytecode-generator.cc

+22-11
Original file line numberDiff line numberDiff line change
@@ -1889,17 +1889,28 @@ bool IsSwitchOptimizable(SwitchStatement* stmt, SwitchInfo* info) {
18891889
}
18901890

18911891
// GCC also jump-table optimizes switch statements with 6 cases or more.
1892-
if (!(static_cast<int>(info->covered_cases.size()) >=
1893-
FLAG_switch_table_min_cases &&
1894-
IsSpreadAcceptable(info->MaxCase() - info->MinCase(),
1895-
cases->length()))) {
1896-
// Invariant- covered_cases has all cases and only cases that will go in the
1897-
// jump table.
1898-
info->covered_cases.clear();
1899-
return false;
1900-
} else {
1901-
return true;
1902-
}
1892+
if (static_cast<int>(info->covered_cases.size()) >=
1893+
FLAG_switch_table_min_cases) {
1894+
// Due to case spread will be used as the size of jump-table,
1895+
// we need to check if it doesn't overflow by casting its
1896+
// min and max bounds to int64_t, and calculate if the difference is less
1897+
// than or equal to INT_MAX.
1898+
int64_t min = static_cast<int64_t>(info->MinCase());
1899+
int64_t max = static_cast<int64_t>(info->MaxCase());
1900+
int64_t spread = max - min + 1;
1901+
1902+
DCHECK_GT(spread, 0);
1903+
1904+
// Check if casted spread is acceptable and doesn't overflow.
1905+
if (spread <= INT_MAX &&
1906+
IsSpreadAcceptable(static_cast<int>(spread), cases->length())) {
1907+
return true;
1908+
}
1909+
}
1910+
// Invariant- covered_cases has all cases and only cases that will go in the
1911+
// jump table.
1912+
info->covered_cases.clear();
1913+
return false;
19031914
}
19041915

19051916
} // namespace

0 commit comments

Comments
 (0)
Please sign in to comment.