Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/utilities/jfrRandom.inline.hpp
41149 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
#ifndef SHARE_JFR_UTILITIES_JFRRANDOM_INLINE_HPP
27
#define SHARE_JFR_UTILITIES_JFRRANDOM_INLINE_HPP
28
29
#include "jfr/utilities/jfrRandom.hpp"
30
31
inline JfrPRNG::JfrPRNG(const void* seed) : _rnd(reinterpret_cast<uint64_t>(seed)) {
32
assert(seed != NULL, "invariant");
33
}
34
35
// Returns the next prng value.
36
// pRNG is: aX+b mod c with a = 0x5DEECE66D, b = 0xB, c = 1<<48
37
// This is the lrand64 generator.
38
inline uint64_t next(uint64_t rnd) {
39
static const uint64_t PrngMult = 0x5DEECE66DLL;
40
static const uint64_t PrngAdd = 0xB;
41
static const uint64_t PrngModPower = 48;
42
static const uint64_t PrngModMask = (static_cast<uint64_t>(1) << PrngModPower) - 1;
43
return (PrngMult * rnd + PrngAdd) & PrngModMask;
44
}
45
46
inline double JfrPRNG::next_uniform() const {
47
_rnd = next(_rnd);
48
// Take the top 26 bits as the random number
49
// (This plus a 1<<58 sampling bound gives a max possible step of
50
// 5194297183973780480 bytes. In this case,
51
// for sample_parameter = 1<<19, max possible step is
52
// 9448372 bytes (24 bits).
53
static const uint64_t PrngModPower = 48; // Number of bits in prng
54
// The uint32_t cast is to prevent a (hard-to-reproduce) NAN
55
// under piii debug for some binaries.
56
// the n_rand value is between 0 and 2**26-1 so it needs to be normalized by dividing by 2**26 (67108864)
57
return (static_cast<uint32_t>(_rnd >> (PrngModPower - 26)) / static_cast<double>(67108864));
58
}
59
60
#endif // SHARE_JFR_UTILITIES_JFRRANDOM_INLINE_HPP
61
62