summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2015-11-20 01:24:59 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2015-11-20 01:24:59 +0000
commitbeb709a2607a00b5df33f0235f22ccdd876cee22 (patch)
treeaff8281b45fba2dbfd0d5049679b59e83b991f9e
parent7dd1260c564c1504a37bfa41e1372868c605ffdd (diff)
parent732f016139acac7bd7ec0d0c1d5e964eb8a28b2e (diff)
Merge "Revert "Use arc4random when available to select delta for image relocation.""
-rw-r--r--runtime/gc/space/image_space.cc5
-rw-r--r--runtime/utils.cc22
-rw-r--r--runtime/utils.h3
3 files changed, 4 insertions, 26 deletions
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index e2b2431054..1fe9a03159 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -58,7 +58,10 @@ static int32_t ChooseRelocationOffsetDelta(int32_t min_delta, int32_t max_delta)
CHECK_ALIGNED(max_delta, kPageSize);
CHECK_LT(min_delta, max_delta);
- int32_t r = GetRandomNumber<int32_t>(min_delta, max_delta);
+ std::default_random_engine generator;
+ generator.seed(NanoTime() * getpid());
+ std::uniform_int_distribution<int32_t> distribution(min_delta, max_delta);
+ int32_t r = distribution(generator);
if (r % 2 == 0) {
r = RoundUp(r, kPageSize);
} else {
diff --git a/runtime/utils.cc b/runtime/utils.cc
index 7da56403e5..68db7e3a73 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -18,14 +18,12 @@
#include <inttypes.h>
#include <pthread.h>
-#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <memory>
-#include <random>
#include "art_field-inl.h"
#include "art_method-inl.h"
@@ -62,26 +60,6 @@ namespace art {
static constexpr bool kUseAddr2line = !kIsTargetBuild;
#endif
-#if defined(__BIONIC__)
-struct Arc4RandomGenerator {
- typedef uint32_t result_type;
- uint32_t min() { return std::numeric_limits<uint32_t>::min(); }
- uint32_t max() { return std::numeric_limits<uint32_t>::max(); }
- uint32_t operator() { return arc4random(); }
-};
-using RNG = Arc4RandomGenerator;
-#else
-using RNG = std::random_device;
-#endif
-
-template <typename T>
-T GetRandomNumber(T min, T max) {
- CHECK_LT(min, max);
- std::uniform_int_distribution<T> dist(min, max);
- RNG rng;
- return dist(rng);
-}
-
pid_t GetTid() {
#if defined(__APPLE__)
uint64_t owner;
diff --git a/runtime/utils.h b/runtime/utils.h
index c3684e0bbb..3690f86a80 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -350,9 +350,6 @@ void ParseDouble(const std::string& option,
double* parsed_value,
UsageFn Usage);
-template <typename T>
-T GetRandomNumber(T min, T max);
-
} // namespace art
#endif // ART_RUNTIME_UTILS_H_