[heap,cctest] Get rid of protected-for-sake-of-testing scope.
authormlippautz <mlippautz@chromium.org>
Fri, 21 Aug 2015 12:40:22 +0000 (05:40 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 21 Aug 2015 12:40:33 +0000 (12:40 +0000)
BUG=

Review URL: https://codereview.chromium.org/1293283003

Cr-Commit-Position: refs/heads/master@{#30301}

src/heap/heap.h
test/cctest/cctest.gyp
test/cctest/cctest.h
test/cctest/heap-tester.h [new file with mode: 0644]
test/cctest/test-alloc.cc
test/cctest/test-api.cc
test/cctest/test-heap.cc
test/cctest/test-mark-compact.cc
test/cctest/test-unboxed-doubles.cc

index 33cb0498f3a174c4fc6e0a2da2c303fddc0ce321..0d7b77d0765723218213ceeecca9b9953574f8cc 100644 (file)
@@ -1618,8 +1618,31 @@ class Heap {
 
   bool ShouldOptimizeForMemoryUsage() { return optimize_for_memory_usage_; }
 
- protected:
-  // Methods made available to tests.
+ private:
+  static const int kInitialStringTableSize = 2048;
+  static const int kInitialEvalCacheSize = 64;
+  static const int kInitialNumberStringCacheSize = 256;
+
+  Heap();
+
+  int current_gc_flags() { return current_gc_flags_; }
+  void set_current_gc_flags(int flags) {
+    current_gc_flags_ = flags;
+    DCHECK(!ShouldFinalizeIncrementalMarking() ||
+           !ShouldAbortIncrementalMarking());
+  }
+
+  inline bool ShouldReduceMemory() const {
+    return current_gc_flags_ & kReduceMemoryFootprintMask;
+  }
+
+  inline bool ShouldAbortIncrementalMarking() const {
+    return current_gc_flags_ & kAbortIncrementalMarkingMask;
+  }
+
+  inline bool ShouldFinalizeIncrementalMarking() const {
+    return current_gc_flags_ & kFinalizeIncrementalMarkingMask;
+  }
 
   // Allocates a JS Map in the heap.
   MUST_USE_RESULT AllocationResult
@@ -1674,32 +1697,6 @@ class Heap {
   MUST_USE_RESULT AllocationResult
       AllocateFixedArray(int length, PretenureFlag pretenure = NOT_TENURED);
 
-  static const int kInitialStringTableSize = 2048;
-  static const int kInitialEvalCacheSize = 64;
-  static const int kInitialNumberStringCacheSize = 256;
-
- private:
-  Heap();
-
-  int current_gc_flags() { return current_gc_flags_; }
-  void set_current_gc_flags(int flags) {
-    current_gc_flags_ = flags;
-    DCHECK(!ShouldFinalizeIncrementalMarking() ||
-           !ShouldAbortIncrementalMarking());
-  }
-
-  inline bool ShouldReduceMemory() const {
-    return current_gc_flags_ & kReduceMemoryFootprintMask;
-  }
-
-  inline bool ShouldAbortIncrementalMarking() const {
-    return current_gc_flags_ & kAbortIncrementalMarkingMask;
-  }
-
-  inline bool ShouldFinalizeIncrementalMarking() const {
-    return current_gc_flags_ & kFinalizeIncrementalMarkingMask;
-  }
-
   // The amount of external memory registered through the API kept alive
   // by global handles
   int64_t amount_of_external_allocated_memory_;
index 10207c1038234e682dd381dacfb510256d449b91..24db817506ce0a59339194672b64368564453e42 100644 (file)
@@ -88,6 +88,7 @@
         'gay-fixed.cc',
         'gay-precision.cc',
         'gay-shortest.cc',
+        'heap-tester.h',
         'print-extension.cc',
         'profiler-extension.cc',
         'test-accessors.cc',
index 48232eed01f19446f2471cdaac6276ab74ba4ac3..40fb2390cd61bd56c35844f6e86abc9d699b4856 100644 (file)
@@ -89,21 +89,6 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
 #undef DEFINE_EXTENSION_FLAG
 
 
-// Use this to expose protected methods in i::Heap.
-class TestHeap : public i::Heap {
- public:
-  using i::Heap::AllocateByteArray;
-  using i::Heap::AllocateFixedArray;
-  using i::Heap::AllocateHeapNumber;
-  using i::Heap::AllocateFloat32x4;
-  using i::Heap::AllocateJSObject;
-  using i::Heap::AllocateJSObjectFromMap;
-  using i::Heap::AllocateMap;
-  using i::Heap::CopyCode;
-  using i::Heap::kInitialNumberStringCacheSize;
-};
-
-
 class CcTest {
  public:
   typedef void (TestFunction)();
@@ -137,10 +122,6 @@ class CcTest {
     return i_isolate()->heap();
   }
 
-  static TestHeap* test_heap() {
-    return reinterpret_cast<TestHeap*>(i_isolate()->heap());
-  }
-
   static v8::base::RandomNumberGenerator* random_number_generator() {
     return InitIsolateOnce()->random_number_generator();
   }
diff --git a/test/cctest/heap-tester.h b/test/cctest/heap-tester.h
new file mode 100644 (file)
index 0000000..fc2e254
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright 2015 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 HEAP_TESTER_H_
+#define HEAP_TESTER_H_
+
+#include "src/handles.h"
+#include "src/heap/spaces.h"
+
+// Tests that should have access to private methods of {v8::internal::Heap}.
+// Those tests need to be defined using HEAP_TEST(Name) { ... }.
+#define HEAP_TEST_METHODS(V) \
+  V(GCFlags)                 \
+  V(MarkCompactCollector)    \
+  V(NoPromotion)             \
+  V(NumberStringCacheSize)   \
+  V(ObjectGroups)            \
+  V(Promotion)               \
+  V(Regression39128)         \
+  V(ResetWeakHandle)         \
+  V(StressHandles)           \
+  V(TestSizeOfObjects)       \
+  V(WriteBarriersInCopyJSObject)
+
+
+#define HEAP_TEST(Name)                                                       \
+  CcTest register_test_##Name(v8::internal::HeapTester::Test##Name, __FILE__, \
+                              #Name, NULL, true, true);                       \
+  void v8::internal::HeapTester::Test##Name()
+
+
+#define THREADED_HEAP_TEST(Name)                                             \
+  RegisterThreadedTest register_##Name(v8::internal::HeapTester::Test##Name, \
+                                       #Name);                               \
+  /* */ HEAP_TEST(Name)
+
+
+namespace v8 {
+namespace internal {
+
+class HeapTester {
+ public:
+#define DECLARE_STATIC(Name) static void Test##Name();
+
+  HEAP_TEST_METHODS(DECLARE_STATIC)
+#undef HEAP_TEST_METHODS
+
+  /* test-alloc.cc */
+  static AllocationResult AllocateAfterFailures();
+  static Handle<Object> TestAllocateAfterFailures();
+
+  /* test-api.cc */
+  static void ResetWeakHandle(bool global_gc);
+};
+}
+}
+
+#endif  // HEAP_TESTER_H_
index 74388d1785047b9319a5a521791a3bb14fc98c09..9c442a79c820cb262ffb91e7e03df2bacb9f3361 100644 (file)
 
 #include "src/accessors.h"
 #include "src/api.h"
+#include "test/cctest/heap-tester.h"
 
 
 using namespace v8::internal;
 
 
-static AllocationResult AllocateAfterFailures() {
+AllocationResult v8::internal::HeapTester::AllocateAfterFailures() {
   static int attempts = 0;
 
   // The first 4 times we simulate a full heap, by returning retry.
   if (++attempts < 4) return AllocationResult::Retry();
 
   // Expose some private stuff on Heap.
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
 
   // Now that we have returned 'retry' 4 times, we are in a last-chance
   // scenario, with always_allocate.  See CALL_AND_RETRY.  Test that all
@@ -97,16 +98,16 @@ static AllocationResult AllocateAfterFailures() {
 }
 
 
-static Handle<Object> Test() {
+Handle<Object> v8::internal::HeapTester::TestAllocateAfterFailures() {
   CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object);
 }
 
 
-TEST(StressHandles) {
+HEAP_TEST(StressHandles) {
   v8::HandleScope scope(CcTest::isolate());
   v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate());
   env->Enter();
-  Handle<Object> o = Test();
+  Handle<Object> o = TestAllocateAfterFailures();
   CHECK(o->IsTrue());
   env->Exit();
 }
@@ -117,7 +118,8 @@ void TestGetter(
     const v8::PropertyCallbackInfo<v8::Value>& info) {
   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
   HandleScope scope(isolate);
-  info.GetReturnValue().Set(v8::Utils::ToLocal(Test()));
+  info.GetReturnValue().Set(v8::Utils::ToLocal(
+      v8::internal::HeapTester::TestAllocateAfterFailures()));
 }
 
 
index da615597f66637fba701c9bea6904694766e8f6c..2e085d1b61b76a66e5c753ecf4646505a43f9827 100644 (file)
@@ -50,6 +50,7 @@
 #include "src/unicode-inl.h"
 #include "src/utils.h"
 #include "src/vm-state.h"
+#include "test/cctest/heap-tester.h"
 
 static const bool kLogThreading = false;
 
@@ -6686,7 +6687,11 @@ static void ResetUseValueAndSetFlag(
 }
 
 
-static void ResetWeakHandle(bool global_gc) {
+void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) {
+  using v8::Context;
+  using v8::Local;
+  using v8::Object;
+
   v8::Isolate* iso = CcTest::isolate();
   v8::HandleScope scope(iso);
   v8::Handle<Context> context = Context::New(iso);
@@ -6701,8 +6706,7 @@ static void ResetWeakHandle(bool global_gc) {
     object_a.handle.Reset(iso, a);
     object_b.handle.Reset(iso, b);
     if (global_gc) {
-      CcTest::heap()->CollectAllGarbage(
-          TestHeap::Heap::kAbortIncrementalMarkingMask);
+      CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
     } else {
       CcTest::heap()->CollectGarbage(i::NEW_SPACE);
     }
@@ -6720,8 +6724,7 @@ static void ResetWeakHandle(bool global_gc) {
     CHECK(object_b.handle.IsIndependent());
   }
   if (global_gc) {
-    CcTest::heap()->CollectAllGarbage(
-        TestHeap::Heap::kAbortIncrementalMarkingMask);
+    CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
   } else {
     CcTest::heap()->CollectGarbage(i::NEW_SPACE);
   }
@@ -6730,9 +6733,9 @@ static void ResetWeakHandle(bool global_gc) {
 }
 
 
-THREADED_TEST(ResetWeakHandle) {
-  ResetWeakHandle(false);
-  ResetWeakHandle(true);
+THREADED_HEAP_TEST(ResetWeakHandle) {
+  v8::internal::HeapTester::ResetWeakHandle(false);
+  v8::internal::HeapTester::ResetWeakHandle(true);
 }
 
 
index f994d9044eefdcf8eeb05b3ad698edef45cd049e..811c4cfa53723c2859a8efd29b9697c8a91e31cc 100644 (file)
 #include "src/macro-assembler.h"
 #include "src/snapshot/snapshot.h"
 #include "test/cctest/cctest.h"
+#include "test/cctest/heap-tester.h"
 
 using v8::Just;
 
 namespace v8 {
 namespace internal {
 
-// Tests that should have access to private methods of {v8::internal::Heap}.
-// Those tests need to be defined using HEAP_TEST(Name) { ... }.
-#define HEAP_TEST_METHODS(V) \
-  V(GCFlags)
-
-
-#define HEAP_TEST(Name)                                                      \
-  CcTest register_test_##Name(HeapTester::Test##Name, __FILE__, #Name, NULL, \
-                              true, true);                                   \
-  void HeapTester::Test##Name()
-
-
-class HeapTester {
- public:
-#define DECLARE_STATIC(Name) static void Test##Name();
-
-  HEAP_TEST_METHODS(DECLARE_STATIC)
-#undef HEAP_TEST_METHODS
-};
-
-
 static void CheckMap(Map* map, int type, int instance_size) {
   CHECK(map->IsHeapObject());
 #ifdef DEBUG
@@ -1148,11 +1128,11 @@ static int LenFromSize(int size) {
 }
 
 
-TEST(Regression39128) {
+HEAP_TEST(Regression39128) {
   // Test case for crbug.com/39128.
   CcTest::InitializeVM();
   Isolate* isolate = CcTest::i_isolate();
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
 
   // Increase the chance of 'bump-the-pointer' allocation in old space.
   heap->CollectAllGarbage();
@@ -1952,7 +1932,7 @@ TEST(TestSizeOfRegExpCode) {
 }
 
 
-TEST(TestSizeOfObjects) {
+HEAP_TEST(TestSizeOfObjects) {
   v8::V8::Initialize();
 
   // Get initial heap size after several full GCs, which will stabilize
@@ -1975,7 +1955,7 @@ TEST(TestSizeOfObjects) {
     AlwaysAllocateScope always_allocate(CcTest::i_isolate());
     int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
     for (int i = 1; i <= 100; i++) {
-      CcTest::test_heap()->AllocateFixedArray(8192, TENURED).ToObjectChecked();
+      CcTest::heap()->AllocateFixedArray(8192, TENURED).ToObjectChecked();
       CHECK_EQ(initial_size + i * filler_size,
                static_cast<int>(CcTest::heap()->SizeOfObjects()));
     }
@@ -5867,13 +5847,13 @@ TEST(Regress442710) {
 }
 
 
-TEST(NumberStringCacheSize) {
+HEAP_TEST(NumberStringCacheSize) {
   // Test that the number-string cache has not been resized in the snapshot.
   CcTest::InitializeVM();
   Isolate* isolate = CcTest::i_isolate();
   if (!isolate->snapshot_available()) return;
   Heap* heap = isolate->heap();
-  CHECK_EQ(TestHeap::kInitialNumberStringCacheSize * 2,
+  CHECK_EQ(Heap::kInitialNumberStringCacheSize * 2,
            heap->number_string_cache()->length());
 }
 
index 73369d29e57fa7a4c31dd86ac1fd026abbea5838..84cb051205eca07f11ad3b41650097fee7b0091d 100644 (file)
@@ -42,6 +42,7 @@
 #include "src/full-codegen/full-codegen.h"
 #include "src/global-handles.h"
 #include "test/cctest/cctest.h"
+#include "test/cctest/heap-tester.h"
 
 using namespace v8::internal;
 using v8::Just;
@@ -74,9 +75,9 @@ TEST(MarkingDeque) {
 }
 
 
-TEST(Promotion) {
+HEAP_TEST(Promotion) {
   CcTest::InitializeVM();
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
   heap->ConfigureHeap(1, 1, 1, 0);
 
   v8::HandleScope sc(CcTest::isolate());
@@ -100,9 +101,9 @@ TEST(Promotion) {
 }
 
 
-TEST(NoPromotion) {
+HEAP_TEST(NoPromotion) {
   CcTest::InitializeVM();
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
   heap->ConfigureHeap(1, 1, 1, 0);
 
   v8::HandleScope sc(CcTest::isolate());
@@ -125,12 +126,12 @@ TEST(NoPromotion) {
 }
 
 
-TEST(MarkCompactCollector) {
+HEAP_TEST(MarkCompactCollector) {
   FLAG_incremental_marking = false;
   FLAG_retain_maps_for_n_gc = 0;
   CcTest::InitializeVM();
   Isolate* isolate = CcTest::i_isolate();
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
   Factory* factory = isolate->factory();
 
   v8::HandleScope sc(CcTest::isolate());
@@ -244,11 +245,11 @@ static void WeakPointerCallback(
 }
 
 
-TEST(ObjectGroups) {
+HEAP_TEST(ObjectGroups) {
   FLAG_incremental_marking = false;
   CcTest::InitializeVM();
   GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
   NumberOfWeakCalls = 0;
   v8::HandleScope handle_scope(CcTest::isolate());
 
index 3a629bdca0e906e4e40babf18869d297f79f1eca..41ce56388e92012efb97146b88beef64b034ca10 100644 (file)
@@ -14,6 +14,7 @@
 #include "src/ic/ic.h"
 #include "src/macro-assembler.h"
 #include "test/cctest/cctest.h"
+#include "test/cctest/heap-tester.h"
 
 using namespace v8::base;
 using namespace v8::internal;
@@ -1402,11 +1403,11 @@ static int LenFromSize(int size) {
 }
 
 
-TEST(WriteBarriersInCopyJSObject) {
+HEAP_TEST(WriteBarriersInCopyJSObject) {
   FLAG_max_semi_space_size = 1;  // Ensure new space is not growing.
   CcTest::InitializeVM();
   Isolate* isolate = CcTest::i_isolate();
-  TestHeap* heap = CcTest::test_heap();
+  Heap* heap = CcTest::heap();
 
   v8::HandleScope scope(CcTest::isolate());