< prev index next >

hotspot/src/share/vm/gc/g1/workerDataArray.cpp

Print this page
rev 11942 : 8165451: Convert WorkerDataArray_test to GTest


  62     } else {
  63       out->print(" -");
  64     }
  65   }
  66   out->cr();
  67 }
  68 
  69 template <>
  70 void WorkerDataArray<size_t>::WDAPrinter::details(const WorkerDataArray<size_t>* phase, outputStream* out) {
  71   out->print("%-25s", "");
  72   for (uint i = 0; i < phase->_length; ++i) {
  73     size_t value = phase->get(i);
  74     if (value != phase->uninitialized()) {
  75       out->print("  " SIZE_FORMAT, phase->get(i));
  76     } else {
  77       out->print(" -");
  78     }
  79   }
  80   out->cr();
  81 }
  82 
  83 #ifndef PRODUCT
  84 
  85 #include "memory/resourceArea.hpp"
  86 
  87 void WorkerDataArray_test_verify_string(const char* expected_string, const char* actual_string) {
  88   const size_t expected_len = strlen(expected_string);
  89 
  90   assert(expected_len == strlen(actual_string),
  91       "Wrong string length, expected " SIZE_FORMAT " but got " SIZE_FORMAT "(Expected '%s' but got: '%s')",
  92       expected_len, strlen(actual_string), expected_string, actual_string);
  93 
  94   // Can't use strncmp here because floating point values use different decimal points for different locales.
  95   // Allow strings to differ in "." vs. "," only. This should still catch most errors.
  96   for (size_t i = 0; i < expected_len; i++) {
  97     char e = expected_string[i];
  98     char a = actual_string[i];
  99     if (e != a) {
 100       if ((e == '.' || e == ',') && (a == '.' || a == ',')) {
 101         // Most likely just a difference in locale
 102       } else {
 103         assert(false, "Expected '%s' but got: '%s'", expected_string, actual_string);
 104       }
 105     }
 106   }
 107 }
 108 
 109 void WorkerDataArray_test_verify_array(WorkerDataArray<size_t>& array, size_t expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) {
 110   const double epsilon = 0.0001;
 111   assert(array.sum() == expected_sum, "Wrong sum, expected: " SIZE_FORMAT " but got: " SIZE_FORMAT, expected_sum, array.sum());
 112   assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average());
 113 
 114   ResourceMark rm;
 115   stringStream out;
 116   array.print_summary_on(&out);
 117   WorkerDataArray_test_verify_string(expected_summary, out.as_string());
 118   out.reset();
 119   array.print_details_on(&out);
 120   WorkerDataArray_test_verify_string(exected_details, out.as_string());
 121 }
 122 
 123 void WorkerDataArray_test_verify_array(WorkerDataArray<double>& array, double expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) {
 124   const double epsilon = 0.0001;
 125   assert(fabs(array.sum() - expected_sum) < epsilon, "Wrong sum, expected: %f but got: %f", expected_sum, array.sum());
 126   assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average());
 127 
 128   ResourceMark rm;
 129   stringStream out;
 130   array.print_summary_on(&out);
 131   WorkerDataArray_test_verify_string(expected_summary, out.as_string());
 132   out.reset();
 133   array.print_details_on(&out);
 134   WorkerDataArray_test_verify_string(exected_details, out.as_string());
 135 }
 136 
 137 void WorkerDataArray_test_basic() {
 138   WorkerDataArray<size_t> array(3, "Test array");
 139   array.set(0, 5);
 140   array.set(1, 3);
 141   array.set(2, 7);
 142 
 143   WorkerDataArray_test_verify_array(array, 15, 5.0,
 144       "Test array                Min: 3, Avg:  5.0, Max: 7, Diff: 4, Sum: 15, Workers: 3\n",
 145       "                           5  3  7\n" );
 146 }
 147 
 148 void WorkerDataArray_test_add() {
 149   WorkerDataArray<size_t> array(3, "Test array");
 150   array.set(0, 5);
 151   array.set(1, 3);
 152   array.set(2, 7);
 153 
 154   for (uint i = 0; i < 3; i++) {
 155     array.add(i, 1);
 156   }
 157 
 158   WorkerDataArray_test_verify_array(array, 18, 6.0,
 159       "Test array                Min: 4, Avg:  6.0, Max: 8, Diff: 4, Sum: 18, Workers: 3\n",
 160       "                           6  4  8\n" );
 161 }
 162 
 163 void WorkerDataArray_test_with_uninitialized() {
 164   WorkerDataArray<size_t> array(3, "Test array");
 165   array.set(0, 5);
 166   array.set(1, WorkerDataArray<size_t>::uninitialized());
 167   array.set(2, 7);
 168 
 169   WorkerDataArray_test_verify_array(array, 12, 6,
 170       "Test array                Min: 5, Avg:  6.0, Max: 7, Diff: 2, Sum: 12, Workers: 2\n",
 171       "                           5 -  7\n" );
 172 }
 173 
 174 void WorkerDataArray_test_uninitialized() {
 175   WorkerDataArray<size_t> array(3, "Test array");
 176   array.set(0, WorkerDataArray<size_t>::uninitialized());
 177   array.set(1, WorkerDataArray<size_t>::uninitialized());
 178   array.set(2, WorkerDataArray<size_t>::uninitialized());
 179 
 180   WorkerDataArray_test_verify_array(array, 0, 0.0,
 181       "Test array                skipped\n",
 182       "                          - - -\n" );
 183 }
 184 
 185 void WorkerDataArray_test_double_with_uninitialized() {
 186   WorkerDataArray<double> array(3, "Test array");
 187   array.set(0, 5.1 / MILLIUNITS);
 188   array.set(1, WorkerDataArray<double>::uninitialized());
 189   array.set(2, 7.2 / MILLIUNITS);
 190 
 191   WorkerDataArray_test_verify_array(array, 12.3 / MILLIUNITS, 6.15 / MILLIUNITS,
 192       "Test array                Min:  5.1, Avg:  6.1, Max:  7.2, Diff:  2.1, Sum: 12.3, Workers: 2\n",
 193       "                           5.1 -  7.2\n" );
 194 }
 195 
 196 void WorkerDataArray_test() {
 197   WorkerDataArray_test_basic();
 198   WorkerDataArray_test_add();
 199   WorkerDataArray_test_with_uninitialized();
 200   WorkerDataArray_test_uninitialized();
 201   WorkerDataArray_test_double_with_uninitialized();
 202 }
 203 
 204 #endif


  62     } else {
  63       out->print(" -");
  64     }
  65   }
  66   out->cr();
  67 }
  68 
  69 template <>
  70 void WorkerDataArray<size_t>::WDAPrinter::details(const WorkerDataArray<size_t>* phase, outputStream* out) {
  71   out->print("%-25s", "");
  72   for (uint i = 0; i < phase->_length; ++i) {
  73     size_t value = phase->get(i);
  74     if (value != phase->uninitialized()) {
  75       out->print("  " SIZE_FORMAT, phase->get(i));
  76     } else {
  77       out->print(" -");
  78     }
  79   }
  80   out->cr();
  81 }



























































































































< prev index next >