mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 12:34:32 +02:00
8009120: Fuzz instruction scheduling in HotSpot compilers
Reviewed-by: kvn, vlivanov
This commit is contained in:
parent
999837eb30
commit
4b638cf955
5 changed files with 61 additions and 7 deletions
|
@ -3669,3 +3669,38 @@ void Compile::add_expensive_node(Node * n) {
|
|||
n->set_req(0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// Auxiliary method to support randomized stressing/fuzzing.
|
||||
//
|
||||
// This method can be called the arbitrary number of times, with current count
|
||||
// as the argument. The logic allows selecting a single candidate from the
|
||||
// running list of candidates as follows:
|
||||
// int count = 0;
|
||||
// Cand* selected = null;
|
||||
// while(cand = cand->next()) {
|
||||
// if (randomized_select(++count)) {
|
||||
// selected = cand;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Including count equalizes the chances any candidate is "selected".
|
||||
// This is useful when we don't have the complete list of candidates to choose
|
||||
// from uniformly. In this case, we need to adjust the randomicity of the
|
||||
// selection, or else we will end up biasing the selection towards the latter
|
||||
// candidates.
|
||||
//
|
||||
// Quick back-envelope calculation shows that for the list of n candidates
|
||||
// the equal probability for the candidate to persist as "best" can be
|
||||
// achieved by replacing it with "next" k-th candidate with the probability
|
||||
// of 1/k. It can be easily shown that by the end of the run, the
|
||||
// probability for any candidate is converged to 1/n, thus giving the
|
||||
// uniform distribution among all the candidates.
|
||||
//
|
||||
// We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
|
||||
#define RANDOMIZED_DOMAIN_POW 29
|
||||
#define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)
|
||||
#define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
|
||||
bool Compile::randomized_select(int count) {
|
||||
assert(count > 0, "only positive");
|
||||
return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue