Mercurial > hg > truffle
comparison src/share/vm/opto/compile.cpp @ 8691:571076d3c79d
8009120: Fuzz instruction scheduling in HotSpot compilers
Reviewed-by: kvn, vlivanov
author | shade |
---|---|
date | Tue, 05 Mar 2013 04:24:50 -0800 |
parents | 8b3da8d14c93 |
children | 8651f608fea4 |
comparison
equal
deleted
inserted
replaced
8689:bf06968a8a00 | 8691:571076d3c79d |
---|---|
3667 // Clear control input and let IGVN optimize expensive nodes if | 3667 // Clear control input and let IGVN optimize expensive nodes if |
3668 // OptimizeExpensiveOps is off. | 3668 // OptimizeExpensiveOps is off. |
3669 n->set_req(0, NULL); | 3669 n->set_req(0, NULL); |
3670 } | 3670 } |
3671 } | 3671 } |
3672 | |
3673 // Auxiliary method to support randomized stressing/fuzzing. | |
3674 // | |
3675 // This method can be called the arbitrary number of times, with current count | |
3676 // as the argument. The logic allows selecting a single candidate from the | |
3677 // running list of candidates as follows: | |
3678 // int count = 0; | |
3679 // Cand* selected = null; | |
3680 // while(cand = cand->next()) { | |
3681 // if (randomized_select(++count)) { | |
3682 // selected = cand; | |
3683 // } | |
3684 // } | |
3685 // | |
3686 // Including count equalizes the chances any candidate is "selected". | |
3687 // This is useful when we don't have the complete list of candidates to choose | |
3688 // from uniformly. In this case, we need to adjust the randomicity of the | |
3689 // selection, or else we will end up biasing the selection towards the latter | |
3690 // candidates. | |
3691 // | |
3692 // Quick back-envelope calculation shows that for the list of n candidates | |
3693 // the equal probability for the candidate to persist as "best" can be | |
3694 // achieved by replacing it with "next" k-th candidate with the probability | |
3695 // of 1/k. It can be easily shown that by the end of the run, the | |
3696 // probability for any candidate is converged to 1/n, thus giving the | |
3697 // uniform distribution among all the candidates. | |
3698 // | |
3699 // We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large. | |
3700 #define RANDOMIZED_DOMAIN_POW 29 | |
3701 #define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW) | |
3702 #define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1) | |
3703 bool Compile::randomized_select(int count) { | |
3704 assert(count > 0, "only positive"); | |
3705 return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count); | |
3706 } |