< prev index next >

test/native/gc/g1/test_workerDataArray.cpp

Print this page
rev 13064 : [mq]: 8178148-ehelin-review


  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/g1/workerDataArray.inline.hpp"
  26 #include "memory/resourceArea.hpp"
  27 #include "unittest.hpp"
  28 #include "utilities/ostream.hpp"
  29 
  30 static const double epsilon = 0.0001;
  31 
  32 template<typename T>
  33 class WorkerDataArrayTest : public ::testing::Test {
  34  protected:
  35   WorkerDataArrayTest() :
  36     title("Test array"),
  37     array(3, title) {




  38   }
  39 
  40   const char* print_summary() {
  41     stringStream out;
  42     array.print_summary_on(&out);
  43     return out.as_string();
  44   }
  45 
  46   const char* print_details() {
  47     stringStream out;
  48     array.print_details_on(&out);
  49     return out.as_string();
  50   }
  51 
  52   const char* print_expected_summary() {
  53     return prepend_with(title, expected_summary());
  54   }
  55 
  56   const char* print_expected_details() {
  57     return prepend_with("", expected_details());
  58   }
  59 
  60   // returns expected summary for array without uninitialized elements
  61   // used it because string representation of double depends on locale
  62   static const char* format_summary(
  63     T min, double avg, T max, T diff, T sum, size_t workers);
  64 
  65   const char* title;
  66   WorkerDataArray<T> array;
  67 



  68  private:
  69   virtual const char* expected_summary() = 0;
  70   virtual const char* expected_details() = 0;
  71 
  72   static const char* prepend_with(const char* str, const char* orig) {
  73     stringStream out;
  74     out.print("%-25s", str);
  75     out.print("%s", orig);
  76     return out.as_string();
  77   }
  78 
  79   ResourceMark rm;
  80 };
  81 
  82 template<>
  83 const char* WorkerDataArrayTest<size_t>::format_summary(
  84   size_t min, double avg, size_t max, size_t diff, size_t sum, size_t workers) {
  85 
  86   stringStream out;
  87   out.print(" Min: " SIZE_FORMAT


  94 
  95 template<>
  96 const char* WorkerDataArrayTest<double>::format_summary(
  97   double min, double avg, double max, double diff, double sum, size_t workers) {
  98 
  99   stringStream out;
 100   out.print(" Min: %4.1lf"
 101             ", Avg: %4.1lf, Max: %4.1lf"
 102             ", Diff: %4.1lf, Sum: %4.1lf"
 103             ", Workers: " SIZE_FORMAT "\n",
 104             min, avg, max, diff, sum, workers);
 105   return out.as_string();
 106 }
 107 
 108 class BasicWorkerDataArrayTest : public WorkerDataArrayTest<size_t> {
 109  protected:
 110   BasicWorkerDataArrayTest() {
 111     array.set(0, 5);
 112     array.set(1, 3);
 113     array.set(2, 7);




 114   }
 115 
 116  private:
 117   virtual const char* expected_summary() {
 118     return format_summary(3, 5.0, 7, 4, 15, 3);
 119   }
 120 
 121   virtual const char* expected_details() {
 122     return "  5  3  7\n";
 123   }
 124 };
 125 
 126 TEST_VM_F(BasicWorkerDataArrayTest, sum_test) {
 127   ASSERT_EQ(15u, array.sum());

 128 }
 129 
 130 TEST_VM_F(BasicWorkerDataArrayTest, average_test) {
 131   ASSERT_NEAR(5.0, array.average(), epsilon);

 132 }
 133 
 134 TEST_VM_F(BasicWorkerDataArrayTest, print_summary_on_test) {
 135   ASSERT_STREQ(print_expected_summary(), print_summary());
 136 }
 137 
 138 TEST_VM_F(BasicWorkerDataArrayTest, print_details_on_test) {
 139   ASSERT_STREQ(print_expected_details(), print_details());
 140 }
 141 
 142 class AddWorkerDataArrayTest : public WorkerDataArrayTest<size_t> {
 143  protected:
 144   AddWorkerDataArrayTest() {
 145     array.set(0, 5);
 146     array.set(1, 3);
 147     array.set(2, 7);
 148 
 149     for (uint i = 0; i < 3; i++) {
 150       array.add(i, 1);
 151     }










 152   }
 153 
 154  private:
 155   virtual const char* expected_summary() {
 156     return format_summary(4, 6.0, 8, 4, 18, 3);
 157   }
 158 
 159   virtual const char* expected_details() {
 160     return "  6  4  8\n";
 161   }
 162 };
 163 
 164 TEST_VM_F(AddWorkerDataArrayTest, sum_test) {
 165   ASSERT_EQ(18u, array.sum());

 166 }
 167 
 168 TEST_VM_F(AddWorkerDataArrayTest, average_test) {
 169   ASSERT_NEAR(6.0, array.average(), epsilon);

 170 }
 171 
 172 TEST_VM_F(AddWorkerDataArrayTest, print_summary_on_test) {
 173   ASSERT_STREQ(print_expected_summary(), print_summary());
 174 }
 175 
 176 TEST_VM_F(AddWorkerDataArrayTest, print_details_on_test) {
 177   ASSERT_STREQ(print_expected_details(), print_details());
 178 }
 179 
 180 class UninitializedElementWorkerDataArrayTest : public WorkerDataArrayTest<size_t> {
 181  protected:
 182   UninitializedElementWorkerDataArrayTest() {
 183     array.set(0, 5);
 184     array.set(1, WorkerDataArray<size_t>::uninitialized());
 185     array.set(2, 7);
 186   }
 187 
 188  private:
 189   virtual const char* expected_summary() {




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/g1/workerDataArray.inline.hpp"
  26 #include "memory/resourceArea.hpp"
  27 #include "unittest.hpp"
  28 #include "utilities/ostream.hpp"
  29 
  30 static const double epsilon = 0.0001;
  31 
  32 template<typename T>
  33 class WorkerDataArrayTest : public ::testing::Test {
  34  protected:
  35   WorkerDataArrayTest() :
  36     title("Test array"),
  37     array(3, title),
  38     sub_item_title("Sub item array"),
  39     sub_item(3, sub_item_title) {
  40 
  41     array.link_thread_work_items(&sub_item);
  42   }
  43 
  44   const char* print_summary() {
  45     stringStream out;
  46     array.print_summary_on(&out);
  47     return out.as_string();
  48   }
  49 
  50   const char* print_details() {
  51     stringStream out;
  52     array.print_details_on(&out);
  53     return out.as_string();
  54   }
  55 
  56   const char* print_expected_summary() {
  57     return prepend_with(title, expected_summary());
  58   }
  59 
  60   const char* print_expected_details() {
  61     return prepend_with("", expected_details());
  62   }
  63 
  64   // returns expected summary for array without uninitialized elements
  65   // used it because string representation of double depends on locale
  66   static const char* format_summary(
  67     T min, double avg, T max, T diff, T sum, size_t workers);
  68 
  69   const char* title;
  70   WorkerDataArray<T> array;
  71 
  72   const char* sub_item_title;
  73   WorkerDataArray<size_t> sub_item;
  74 
  75  private:
  76   virtual const char* expected_summary() = 0;
  77   virtual const char* expected_details() = 0;
  78 
  79   static const char* prepend_with(const char* str, const char* orig) {
  80     stringStream out;
  81     out.print("%-25s", str);
  82     out.print("%s", orig);
  83     return out.as_string();
  84   }
  85 
  86   ResourceMark rm;
  87 };
  88 
  89 template<>
  90 const char* WorkerDataArrayTest<size_t>::format_summary(
  91   size_t min, double avg, size_t max, size_t diff, size_t sum, size_t workers) {
  92 
  93   stringStream out;
  94   out.print(" Min: " SIZE_FORMAT


 101 
 102 template<>
 103 const char* WorkerDataArrayTest<double>::format_summary(
 104   double min, double avg, double max, double diff, double sum, size_t workers) {
 105 
 106   stringStream out;
 107   out.print(" Min: %4.1lf"
 108             ", Avg: %4.1lf, Max: %4.1lf"
 109             ", Diff: %4.1lf, Sum: %4.1lf"
 110             ", Workers: " SIZE_FORMAT "\n",
 111             min, avg, max, diff, sum, workers);
 112   return out.as_string();
 113 }
 114 
 115 class BasicWorkerDataArrayTest : public WorkerDataArrayTest<size_t> {
 116  protected:
 117   BasicWorkerDataArrayTest() {
 118     array.set(0, 5);
 119     array.set(1, 3);
 120     array.set(2, 7);
 121 
 122     array.set_thread_work_item(0, 1);
 123     array.set_thread_work_item(1, 2);
 124     array.set_thread_work_item(2, 3);
 125   }
 126 
 127  private:
 128   virtual const char* expected_summary() {
 129     return format_summary(3, 5.0, 7, 4, 15, 3);
 130   }
 131 
 132   virtual const char* expected_details() {
 133     return "  5  3  7\n";
 134   }
 135 };
 136 
 137 TEST_VM_F(BasicWorkerDataArrayTest, sum_test) {
 138   ASSERT_EQ(15u, array.sum());
 139   ASSERT_EQ(6u, array.thread_work_items(0)->sum());
 140 }
 141 
 142 TEST_VM_F(BasicWorkerDataArrayTest, average_test) {
 143   ASSERT_NEAR(5.0, array.average(), epsilon);
 144   ASSERT_NEAR(2.0, array.thread_work_items(0)->average(), epsilon);
 145 }
 146 
 147 TEST_VM_F(BasicWorkerDataArrayTest, print_summary_on_test) {
 148   ASSERT_STREQ(print_expected_summary(), print_summary());
 149 }
 150 
 151 TEST_VM_F(BasicWorkerDataArrayTest, print_details_on_test) {
 152   ASSERT_STREQ(print_expected_details(), print_details());
 153 }
 154 
 155 class AddWorkerDataArrayTest : public WorkerDataArrayTest<size_t> {
 156  protected:
 157   AddWorkerDataArrayTest() {
 158     array.set(0, 5);
 159     array.set(1, 3);
 160     array.set(2, 7);
 161 
 162     for (uint i = 0; i < 3; i++) {
 163       array.add(i, 1);
 164     }
 165 
 166     WorkerDataArray<size_t>* sub_items = array.thread_work_items(0);
 167 
 168     sub_items->set(0, 1);
 169     sub_items->set(1, 2);
 170     sub_items->set(2, 3);
 171 
 172     for (uint i = 0; i < 3; i++) {
 173       array.add_thread_work_item(i, 1);
 174     }
 175   }
 176 
 177  private:
 178   virtual const char* expected_summary() {
 179     return format_summary(4, 6.0, 8, 4, 18, 3);
 180   }
 181 
 182   virtual const char* expected_details() {
 183     return "  6  4  8\n";
 184   }
 185 };
 186 
 187 TEST_VM_F(AddWorkerDataArrayTest, sum_test) {
 188   ASSERT_EQ(18u, array.sum());
 189   ASSERT_EQ(9u, array.thread_work_items(0)->sum());
 190 }
 191 
 192 TEST_VM_F(AddWorkerDataArrayTest, average_test) {
 193   ASSERT_NEAR(6.0, array.average(), epsilon);
 194   ASSERT_NEAR(3.0, array.thread_work_items(0)->average(), epsilon);
 195 }
 196 
 197 TEST_VM_F(AddWorkerDataArrayTest, print_summary_on_test) {
 198   ASSERT_STREQ(print_expected_summary(), print_summary());
 199 }
 200 
 201 TEST_VM_F(AddWorkerDataArrayTest, print_details_on_test) {
 202   ASSERT_STREQ(print_expected_details(), print_details());
 203 }
 204 
 205 class UninitializedElementWorkerDataArrayTest : public WorkerDataArrayTest<size_t> {
 206  protected:
 207   UninitializedElementWorkerDataArrayTest() {
 208     array.set(0, 5);
 209     array.set(1, WorkerDataArray<size_t>::uninitialized());
 210     array.set(2, 7);
 211   }
 212 
 213  private:
 214   virtual const char* expected_summary() {


< prev index next >