< prev index next >

```rev 49244 : [mq]: event-only
rev 49247 : [mq]: event5```

```@@ -25,17 +25,18 @@
#include "runtime/sharedRuntime.hpp"

// Cheap random number generator

// Statics for the fast log
static const int FastLogNumBits = 10;
static const int FastLogMask = (1 << FastLogNumBits) - 1;
-static double _log_table[1<<FastLogNumBits];  // Constant
+static double log_table[1<<FastLogNumBits];  // Constant
+static bool log_table_initialized;

// Returns the next prng value.
// pRNG is: aX+b mod c with a = 0x5DEECE66D, b =  0xB, c = 1<<48
// This is the lrand64 generator.
static uint64_t next_random(uint64_t rnd) {
```

```@@ -51,11 +52,11 @@
uint64_t x = 0;
memcpy(&x, &d, sizeof(uint64_t));
const uint32_t x_high = x >> 32;
const uint32_t y = x_high >> (20 - FastLogNumBits) & FastLogMask;
const int32_t exponent = ((x_high >> 20) & 0x7FF) - 1023;
-  return exponent + _log_table[y];
+  return exponent + log_table[y];
}

// Generates a geometric variable with the specified mean (512K by default).
// This is done by generating a random number between 0 and 1 and applying
// the inverse cumulative distribution function for an exponential.
```

```@@ -84,11 +85,11 @@
// The value 26.000705 is used rather than 26 to compensate
// for inaccuracies in FastLog2 which otherwise result in a
double log_val = (fast_log2(q) - 26);
size_t rate = static_cast<size_t>(
-      (0.0 < log_val ? 0.0 : log_val) * (-log(2.0) * (_monitoring_rate)) + 1);
+      (0.0 < log_val ? 0.0 : log_val) * (-log(2.0) * (_sampling_rate)) + 1);
_bytes_until_sample = rate;

// Try to correct sample size by removing extra space from last allocation.
if (overflowed_bytes > 0 && _bytes_until_sample > overflowed_bytes) {
_bytes_until_sample -= overflowed_bytes;
```

```@@ -109,14 +110,29 @@

size_t overflow_bytes = total_allocated_bytes - _bytes_until_sample;
pick_next_sample(overflow_bytes);
}

-  if (monitoring_rate == 0) {
+
+  if (log_table_initialized) {
+    return;
+  }
+
+  for (int i = 0; i < (1 << FastLogNumBits); i++) {
+    log_table[i] = (log(1.0 + static_cast<double>(i+0.5) / (1 << FastLogNumBits))
+                     / log(2.0));
+  }
+
+  log_table_initialized = true;
+}
+