Revision: 23316
Author: [email protected]
Date: Fri Aug 22 13:26:29 2014 UTC
Log: First tests for GCIdleTimeHandler.
BUG=
[email protected]
Review URL: https://codereview.chromium.org/496273002
https://code.google.com/p/v8/source/detail?r=23316
Added:
/branches/bleeding_edge/test/heap-unittests/heap-unittest.h
Modified:
/branches/bleeding_edge/src/heap/gc-idle-time-handler.cc
/branches/bleeding_edge/src/heap/gc-idle-time-handler.h
/branches/bleeding_edge/test/heap-unittests/heap-unittest.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/heap-unittests/heap-unittest.h Fri Aug 22
13:26:29 2014 UTC
@@ -0,0 +1,42 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_HEAP_UNITTESTS_HEAP_UNITTEST_H_
+#define V8_HEAP_UNITTESTS_HEAP_UNITTEST_H_
+
+#include "src/heap/gc-idle-time-handler.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+class GCIdleTimeHandlerTest : public ::testing::Test {
+ public:
+ GCIdleTimeHandlerTest() {}
+ virtual ~GCIdleTimeHandlerTest() {}
+
+ GCIdleTimeHandler* handler() { return &handler_; }
+
+ GCIdleTimeHandler::HeapState DefaultHeapState() {
+ GCIdleTimeHandler::HeapState result;
+ result.contexts_disposed = 0;
+ result.size_of_objects = kSizeOfObjects;
+ result.incremental_marking_stopped = false;
+ result.can_start_incremental_marking = true;
+ result.sweeping_in_progress = false;
+ result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed;
+ result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed;
+ return result;
+ }
+
+ static const size_t kSizeOfObjects = 100 * MB;
+ static const size_t kMarkCompactSpeed = 100 * KB;
+ static const size_t kMarkingSpeed = 100 * KB;
+
+ private:
+ GCIdleTimeHandler handler_;
+};
+}
+}
+#endif // V8_HEAP_UNITTESTS_HEAP_UNITTEST_H_
=======================================
--- /branches/bleeding_edge/src/heap/gc-idle-time-handler.cc Fri Aug 22
13:02:11 2014 UTC
+++ /branches/bleeding_edge/src/heap/gc-idle-time-handler.cc Fri Aug 22
13:26:29 2014 UTC
@@ -12,6 +12,8 @@
const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9;
const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000000;
const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100;
+const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7;
+const int GCIdleTimeHandler::kIdleScavengeThreshold = 5;
size_t GCIdleTimeHandler::EstimateMarkingStepSize(
=======================================
--- /branches/bleeding_edge/src/heap/gc-idle-time-handler.h Fri Aug 22
13:02:11 2014 UTC
+++ /branches/bleeding_edge/src/heap/gc-idle-time-handler.h Fri Aug 22
13:26:29 2014 UTC
@@ -89,6 +89,13 @@
// sweeper threads.
static const size_t kMinTimeForFinalizeSweeping;
+ // Number of idle mark-compact events, after which idle handler will
finish
+ // idle round.
+ static const int kMaxMarkCompactsInIdleRound;
+
+ // Number of scavenges that will trigger start of new idle round.
+ static const int kIdleScavengeThreshold;
+
struct HeapState {
int contexts_disposed;
size_t size_of_objects;
@@ -133,8 +140,6 @@
return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold;
}
- static const int kMaxMarkCompactsInIdleRound = 7;
- static const int kIdleScavengeThreshold = 5;
int mark_compacts_since_idle_round_started_;
int scavenges_since_last_idle_round_;
=======================================
--- /branches/bleeding_edge/test/heap-unittests/heap-unittest.cc Thu Aug 21
14:42:22 2014 UTC
+++ /branches/bleeding_edge/test/heap-unittests/heap-unittest.cc Fri Aug 22
13:26:29 2014 UTC
@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "test/heap-unittests/heap-unittest.h"
+
#include <limits>
-#include "src/heap/gc-idle-time-handler.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
@@ -68,6 +67,144 @@
size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time);
}
+
+
+TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.contexts_disposed = 1;
+ heap_state.incremental_marking_stopped = true;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ int idle_time_ms = (heap_state.size_of_objects + speed - 1) / speed;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FULL_GC, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.contexts_disposed = 1;
+ heap_state.incremental_marking_stopped = true;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ int idle_time_ms = heap_state.size_of_objects / speed - 1;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.contexts_disposed = 1;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ int idle_time_ms = heap_state.size_of_objects / speed - 1;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
+ int idle_time_ms = 10;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_GT(speed * idle_time_ms, action.parameter);
+ EXPECT_LT(0, action.parameter);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
+ int idle_time_ms = 10;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_GT(speed * idle_time_ms, action.parameter);
+ EXPECT_LT(0, action.parameter);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ int idle_time_ms = heap_state.size_of_objects / speed - 1;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, StopEventually1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ int idle_time_ms = heap_state.size_of_objects / speed + 1;
+ for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++)
{
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FULL_GC, action.type);
+ handler()->NotifyIdleMarkCompact();
+ }
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ int idle_time_ms = 10;
+ for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++)
{
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ handler()->NotifyIdleMarkCompact();
+ }
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ int idle_time_ms = heap_state.size_of_objects / speed + 1;
+ for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++)
{
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FULL_GC, action.type);
+ handler()->NotifyIdleMarkCompact();
+ }
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ // Emulate mutator work.
+ for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
+ handler()->NotifyScavenge();
+ }
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FULL_GC, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ int idle_time_ms = 10;
+ for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++)
{
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ if (action.type == DO_NOTHING) break;
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ handler()->NotifyIdleMarkCompact();
+ }
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ // Emulate mutator work.
+ for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
+ handler()->NotifyScavenge();
+ }
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+}
+
} // namespace internal
} // namespace v8
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.