| OLD | NEW | 
|    1 // Copyright 2014 the V8 project authors. All rights reserved. |    1 // Copyright 2014 the V8 project authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "src/compiler/zone-stats.h" |    5 #include "src/compiler/zone-stats.h" | 
|    6 #include "src/base/utils/random-number-generator.h" |    6 #include "src/base/utils/random-number-generator.h" | 
|    7 #include "test/unittests/test-utils.h" |    7 #include "test/unittests/test-utils.h" | 
|    8  |    8  | 
|    9 namespace v8 { |    9 namespace v8 { | 
|   10 namespace internal { |   10 namespace internal { | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   44 }; |   44 }; | 
|   45  |   45  | 
|   46 TEST_F(ZoneStatsTest, Empty) { |   46 TEST_F(ZoneStatsTest, Empty) { | 
|   47   ExpectForPool(0, 0, 0); |   47   ExpectForPool(0, 0, 0); | 
|   48   { |   48   { | 
|   49     ZoneStats::StatsScope stats(zone_stats()); |   49     ZoneStats::StatsScope stats(zone_stats()); | 
|   50     Expect(&stats, 0, 0, 0); |   50     Expect(&stats, 0, 0, 0); | 
|   51   } |   51   } | 
|   52   ExpectForPool(0, 0, 0); |   52   ExpectForPool(0, 0, 0); | 
|   53   { |   53   { | 
|   54     ZoneStats::Scope scope(zone_stats()); |   54     ZoneStats::Scope scope(zone_stats(), ZONE_NAME); | 
|   55     scope.zone(); |   55     scope.zone(); | 
|   56   } |   56   } | 
|   57   ExpectForPool(0, 0, 0); |   57   ExpectForPool(0, 0, 0); | 
|   58 } |   58 } | 
|   59  |   59  | 
|   60 TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) { |   60 TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) { | 
|   61   static const size_t kArraySize = 10; |   61   static const size_t kArraySize = 10; | 
|   62  |   62  | 
|   63   ZoneStats::Scope* scopes[kArraySize]; |   63   ZoneStats::Scope* scopes[kArraySize]; | 
|   64  |   64  | 
|   65   // Initialize. |   65   // Initialize. | 
|   66   size_t before_stats = 0; |   66   size_t before_stats = 0; | 
|   67   for (size_t i = 0; i < kArraySize; ++i) { |   67   for (size_t i = 0; i < kArraySize; ++i) { | 
|   68     scopes[i] = new ZoneStats::Scope(zone_stats()); |   68     scopes[i] = new ZoneStats::Scope(zone_stats(), ZONE_NAME); | 
|   69     before_stats += Allocate(scopes[i]->zone());  // Add some stuff. |   69     before_stats += Allocate(scopes[i]->zone());  // Add some stuff. | 
|   70   } |   70   } | 
|   71  |   71  | 
|   72   ExpectForPool(before_stats, before_stats, before_stats); |   72   ExpectForPool(before_stats, before_stats, before_stats); | 
|   73  |   73  | 
|   74   ZoneStats::StatsScope stats(zone_stats()); |   74   ZoneStats::StatsScope stats(zone_stats()); | 
|   75  |   75  | 
|   76   size_t before_deletion = 0; |   76   size_t before_deletion = 0; | 
|   77   for (size_t i = 0; i < kArraySize; ++i) { |   77   for (size_t i = 0; i < kArraySize; ++i) { | 
|   78     before_deletion += Allocate(scopes[i]->zone());  // Add some stuff. |   78     before_deletion += Allocate(scopes[i]->zone());  // Add some stuff. | 
|   79   } |   79   } | 
|   80  |   80  | 
|   81   Expect(&stats, before_deletion, before_deletion, before_deletion); |   81   Expect(&stats, before_deletion, before_deletion, before_deletion); | 
|   82   ExpectForPool(before_stats + before_deletion, before_stats + before_deletion, |   82   ExpectForPool(before_stats + before_deletion, before_stats + before_deletion, | 
|   83                 before_stats + before_deletion); |   83                 before_stats + before_deletion); | 
|   84  |   84  | 
|   85   // Delete the scopes and create new ones. |   85   // Delete the scopes and create new ones. | 
|   86   for (size_t i = 0; i < kArraySize; ++i) { |   86   for (size_t i = 0; i < kArraySize; ++i) { | 
|   87     delete scopes[i]; |   87     delete scopes[i]; | 
|   88     scopes[i] = new ZoneStats::Scope(zone_stats()); |   88     scopes[i] = new ZoneStats::Scope(zone_stats(), ZONE_NAME); | 
|   89   } |   89   } | 
|   90  |   90  | 
|   91   Expect(&stats, 0, before_deletion, before_deletion); |   91   Expect(&stats, 0, before_deletion, before_deletion); | 
|   92   ExpectForPool(0, before_stats + before_deletion, |   92   ExpectForPool(0, before_stats + before_deletion, | 
|   93                 before_stats + before_deletion); |   93                 before_stats + before_deletion); | 
|   94  |   94  | 
|   95   size_t after_deletion = 0; |   95   size_t after_deletion = 0; | 
|   96   for (size_t i = 0; i < kArraySize; ++i) { |   96   for (size_t i = 0; i < kArraySize; ++i) { | 
|   97     after_deletion += Allocate(scopes[i]->zone());  // Add some stuff. |   97     after_deletion += Allocate(scopes[i]->zone());  // Add some stuff. | 
|   98   } |   98   } | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  113   ExpectForPool(0, std::max(after_deletion, before_stats + before_deletion), |  113   ExpectForPool(0, std::max(after_deletion, before_stats + before_deletion), | 
|  114                 before_stats + before_deletion + after_deletion); |  114                 before_stats + before_deletion + after_deletion); | 
|  115 } |  115 } | 
|  116  |  116  | 
|  117 TEST_F(ZoneStatsTest, SimpleAllocationLoop) { |  117 TEST_F(ZoneStatsTest, SimpleAllocationLoop) { | 
|  118   int runs = 20; |  118   int runs = 20; | 
|  119   size_t total_allocated = 0; |  119   size_t total_allocated = 0; | 
|  120   size_t max_loop_allocation = 0; |  120   size_t max_loop_allocation = 0; | 
|  121   ZoneStats::StatsScope outer_stats(zone_stats()); |  121   ZoneStats::StatsScope outer_stats(zone_stats()); | 
|  122   { |  122   { | 
|  123     ZoneStats::Scope outer_scope(zone_stats()); |  123     ZoneStats::Scope outer_scope(zone_stats(), ZONE_NAME); | 
|  124     size_t outer_allocated = 0; |  124     size_t outer_allocated = 0; | 
|  125     for (int i = 0; i < runs; ++i) { |  125     for (int i = 0; i < runs; ++i) { | 
|  126       { |  126       { | 
|  127         size_t bytes = Allocate(outer_scope.zone()); |  127         size_t bytes = Allocate(outer_scope.zone()); | 
|  128         outer_allocated += bytes; |  128         outer_allocated += bytes; | 
|  129         total_allocated += bytes; |  129         total_allocated += bytes; | 
|  130       } |  130       } | 
|  131       ZoneStats::StatsScope inner_stats(zone_stats()); |  131       ZoneStats::StatsScope inner_stats(zone_stats()); | 
|  132       size_t allocated = 0; |  132       size_t allocated = 0; | 
|  133       { |  133       { | 
|  134         ZoneStats::Scope inner_scope(zone_stats()); |  134         ZoneStats::Scope inner_scope(zone_stats(), ZONE_NAME); | 
|  135         for (int j = 0; j < 20; ++j) { |  135         for (int j = 0; j < 20; ++j) { | 
|  136           size_t bytes = Allocate(inner_scope.zone()); |  136           size_t bytes = Allocate(inner_scope.zone()); | 
|  137           allocated += bytes; |  137           allocated += bytes; | 
|  138           total_allocated += bytes; |  138           total_allocated += bytes; | 
|  139           max_loop_allocation = |  139           max_loop_allocation = | 
|  140               std::max(max_loop_allocation, outer_allocated + allocated); |  140               std::max(max_loop_allocation, outer_allocated + allocated); | 
|  141           Expect(&inner_stats, allocated, allocated, allocated); |  141           Expect(&inner_stats, allocated, allocated, allocated); | 
|  142           Expect(&outer_stats, outer_allocated + allocated, max_loop_allocation, |  142           Expect(&outer_stats, outer_allocated + allocated, max_loop_allocation, | 
|  143                  total_allocated); |  143                  total_allocated); | 
|  144           ExpectForPool(outer_allocated + allocated, max_loop_allocation, |  144           ExpectForPool(outer_allocated + allocated, max_loop_allocation, | 
|  145                         total_allocated); |  145                         total_allocated); | 
|  146         } |  146         } | 
|  147       } |  147       } | 
|  148       Expect(&inner_stats, 0, allocated, allocated); |  148       Expect(&inner_stats, 0, allocated, allocated); | 
|  149       Expect(&outer_stats, outer_allocated, max_loop_allocation, |  149       Expect(&outer_stats, outer_allocated, max_loop_allocation, | 
|  150              total_allocated); |  150              total_allocated); | 
|  151       ExpectForPool(outer_allocated, max_loop_allocation, total_allocated); |  151       ExpectForPool(outer_allocated, max_loop_allocation, total_allocated); | 
|  152     } |  152     } | 
|  153   } |  153   } | 
|  154   Expect(&outer_stats, 0, max_loop_allocation, total_allocated); |  154   Expect(&outer_stats, 0, max_loop_allocation, total_allocated); | 
|  155   ExpectForPool(0, max_loop_allocation, total_allocated); |  155   ExpectForPool(0, max_loop_allocation, total_allocated); | 
|  156 } |  156 } | 
|  157  |  157  | 
|  158 }  // namespace compiler |  158 }  // namespace compiler | 
|  159 }  // namespace internal |  159 }  // namespace internal | 
|  160 }  // namespace v8 |  160 }  // namespace v8 | 
| OLD | NEW |