Commit 477f5a81 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap,cctest] Get rid of protected-for-sake-of-testing scope.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#30301}
parent 24ef80dc
...@@ -1618,8 +1618,31 @@ class Heap { ...@@ -1618,8 +1618,31 @@ class Heap {
bool ShouldOptimizeForMemoryUsage() { return optimize_for_memory_usage_; } bool ShouldOptimizeForMemoryUsage() { return optimize_for_memory_usage_; }
protected: private:
// Methods made available to tests. 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. // Allocates a JS Map in the heap.
MUST_USE_RESULT AllocationResult MUST_USE_RESULT AllocationResult
...@@ -1674,32 +1697,6 @@ class Heap { ...@@ -1674,32 +1697,6 @@ class Heap {
MUST_USE_RESULT AllocationResult MUST_USE_RESULT AllocationResult
AllocateFixedArray(int length, PretenureFlag pretenure = NOT_TENURED); 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 // The amount of external memory registered through the API kept alive
// by global handles // by global handles
int64_t amount_of_external_allocated_memory_; int64_t amount_of_external_allocated_memory_;
......
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
'gay-fixed.cc', 'gay-fixed.cc',
'gay-precision.cc', 'gay-precision.cc',
'gay-shortest.cc', 'gay-shortest.cc',
'heap-tester.h',
'print-extension.cc', 'print-extension.cc',
'profiler-extension.cc', 'profiler-extension.cc',
'test-accessors.cc', 'test-accessors.cc',
......
...@@ -89,21 +89,6 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags; ...@@ -89,21 +89,6 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
#undef DEFINE_EXTENSION_FLAG #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 { class CcTest {
public: public:
typedef void (TestFunction)(); typedef void (TestFunction)();
...@@ -137,10 +122,6 @@ class CcTest { ...@@ -137,10 +122,6 @@ class CcTest {
return i_isolate()->heap(); return i_isolate()->heap();
} }
static TestHeap* test_heap() {
return reinterpret_cast<TestHeap*>(i_isolate()->heap());
}
static v8::base::RandomNumberGenerator* random_number_generator() { static v8::base::RandomNumberGenerator* random_number_generator() {
return InitIsolateOnce()->random_number_generator(); return InitIsolateOnce()->random_number_generator();
} }
......
// 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_
...@@ -30,19 +30,20 @@ ...@@ -30,19 +30,20 @@
#include "src/accessors.h" #include "src/accessors.h"
#include "src/api.h" #include "src/api.h"
#include "test/cctest/heap-tester.h"
using namespace v8::internal; using namespace v8::internal;
static AllocationResult AllocateAfterFailures() { AllocationResult v8::internal::HeapTester::AllocateAfterFailures() {
static int attempts = 0; static int attempts = 0;
// The first 4 times we simulate a full heap, by returning retry. // The first 4 times we simulate a full heap, by returning retry.
if (++attempts < 4) return AllocationResult::Retry(); if (++attempts < 4) return AllocationResult::Retry();
// Expose some private stuff on Heap. // 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 // 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 // scenario, with always_allocate. See CALL_AND_RETRY. Test that all
...@@ -97,16 +98,16 @@ static AllocationResult AllocateAfterFailures() { ...@@ -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); CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object);
} }
TEST(StressHandles) { HEAP_TEST(StressHandles) {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate());
env->Enter(); env->Enter();
Handle<Object> o = Test(); Handle<Object> o = TestAllocateAfterFailures();
CHECK(o->IsTrue()); CHECK(o->IsTrue());
env->Exit(); env->Exit();
} }
...@@ -117,7 +118,8 @@ void TestGetter( ...@@ -117,7 +118,8 @@ void TestGetter(
const v8::PropertyCallbackInfo<v8::Value>& info) { const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate); HandleScope scope(isolate);
info.GetReturnValue().Set(v8::Utils::ToLocal(Test())); info.GetReturnValue().Set(v8::Utils::ToLocal(
v8::internal::HeapTester::TestAllocateAfterFailures()));
} }
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "src/unicode-inl.h" #include "src/unicode-inl.h"
#include "src/utils.h" #include "src/utils.h"
#include "src/vm-state.h" #include "src/vm-state.h"
#include "test/cctest/heap-tester.h"
static const bool kLogThreading = false; static const bool kLogThreading = false;
...@@ -6686,7 +6687,11 @@ static void ResetUseValueAndSetFlag( ...@@ -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::Isolate* iso = CcTest::isolate();
v8::HandleScope scope(iso); v8::HandleScope scope(iso);
v8::Handle<Context> context = Context::New(iso); v8::Handle<Context> context = Context::New(iso);
...@@ -6701,8 +6706,7 @@ static void ResetWeakHandle(bool global_gc) { ...@@ -6701,8 +6706,7 @@ static void ResetWeakHandle(bool global_gc) {
object_a.handle.Reset(iso, a); object_a.handle.Reset(iso, a);
object_b.handle.Reset(iso, b); object_b.handle.Reset(iso, b);
if (global_gc) { if (global_gc) {
CcTest::heap()->CollectAllGarbage( CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
TestHeap::Heap::kAbortIncrementalMarkingMask);
} else { } else {
CcTest::heap()->CollectGarbage(i::NEW_SPACE); CcTest::heap()->CollectGarbage(i::NEW_SPACE);
} }
...@@ -6720,8 +6724,7 @@ static void ResetWeakHandle(bool global_gc) { ...@@ -6720,8 +6724,7 @@ static void ResetWeakHandle(bool global_gc) {
CHECK(object_b.handle.IsIndependent()); CHECK(object_b.handle.IsIndependent());
} }
if (global_gc) { if (global_gc) {
CcTest::heap()->CollectAllGarbage( CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
TestHeap::Heap::kAbortIncrementalMarkingMask);
} else { } else {
CcTest::heap()->CollectGarbage(i::NEW_SPACE); CcTest::heap()->CollectGarbage(i::NEW_SPACE);
} }
...@@ -6730,9 +6733,9 @@ static void ResetWeakHandle(bool global_gc) { ...@@ -6730,9 +6733,9 @@ static void ResetWeakHandle(bool global_gc) {
} }
THREADED_TEST(ResetWeakHandle) { THREADED_HEAP_TEST(ResetWeakHandle) {
ResetWeakHandle(false); v8::internal::HeapTester::ResetWeakHandle(false);
ResetWeakHandle(true); v8::internal::HeapTester::ResetWeakHandle(true);
} }
......
...@@ -39,33 +39,13 @@ ...@@ -39,33 +39,13 @@
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
#include "src/snapshot/snapshot.h" #include "src/snapshot/snapshot.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
#include "test/cctest/heap-tester.h"
using v8::Just; using v8::Just;
namespace v8 { namespace v8 {
namespace internal { 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) { static void CheckMap(Map* map, int type, int instance_size) {
CHECK(map->IsHeapObject()); CHECK(map->IsHeapObject());
#ifdef DEBUG #ifdef DEBUG
...@@ -1148,11 +1128,11 @@ static int LenFromSize(int size) { ...@@ -1148,11 +1128,11 @@ static int LenFromSize(int size) {
} }
TEST(Regression39128) { HEAP_TEST(Regression39128) {
// Test case for crbug.com/39128. // Test case for crbug.com/39128.
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); 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. // Increase the chance of 'bump-the-pointer' allocation in old space.
heap->CollectAllGarbage(); heap->CollectAllGarbage();
...@@ -1952,7 +1932,7 @@ TEST(TestSizeOfRegExpCode) { ...@@ -1952,7 +1932,7 @@ TEST(TestSizeOfRegExpCode) {
} }
TEST(TestSizeOfObjects) { HEAP_TEST(TestSizeOfObjects) {
v8::V8::Initialize(); v8::V8::Initialize();
// Get initial heap size after several full GCs, which will stabilize // Get initial heap size after several full GCs, which will stabilize
...@@ -1975,7 +1955,7 @@ TEST(TestSizeOfObjects) { ...@@ -1975,7 +1955,7 @@ TEST(TestSizeOfObjects) {
AlwaysAllocateScope always_allocate(CcTest::i_isolate()); AlwaysAllocateScope always_allocate(CcTest::i_isolate());
int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
for (int i = 1; i <= 100; i++) { 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, CHECK_EQ(initial_size + i * filler_size,
static_cast<int>(CcTest::heap()->SizeOfObjects())); static_cast<int>(CcTest::heap()->SizeOfObjects()));
} }
...@@ -5867,13 +5847,13 @@ TEST(Regress442710) { ...@@ -5867,13 +5847,13 @@ TEST(Regress442710) {
} }
TEST(NumberStringCacheSize) { HEAP_TEST(NumberStringCacheSize) {
// Test that the number-string cache has not been resized in the snapshot. // Test that the number-string cache has not been resized in the snapshot.
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
if (!isolate->snapshot_available()) return; if (!isolate->snapshot_available()) return;
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
CHECK_EQ(TestHeap::kInitialNumberStringCacheSize * 2, CHECK_EQ(Heap::kInitialNumberStringCacheSize * 2,
heap->number_string_cache()->length()); heap->number_string_cache()->length());
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "src/full-codegen/full-codegen.h" #include "src/full-codegen/full-codegen.h"
#include "src/global-handles.h" #include "src/global-handles.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
#include "test/cctest/heap-tester.h"
using namespace v8::internal; using namespace v8::internal;
using v8::Just; using v8::Just;
...@@ -74,9 +75,9 @@ TEST(MarkingDeque) { ...@@ -74,9 +75,9 @@ TEST(MarkingDeque) {
} }
TEST(Promotion) { HEAP_TEST(Promotion) {
CcTest::InitializeVM(); CcTest::InitializeVM();
TestHeap* heap = CcTest::test_heap(); Heap* heap = CcTest::heap();
heap->ConfigureHeap(1, 1, 1, 0); heap->ConfigureHeap(1, 1, 1, 0);
v8::HandleScope sc(CcTest::isolate()); v8::HandleScope sc(CcTest::isolate());
...@@ -100,9 +101,9 @@ TEST(Promotion) { ...@@ -100,9 +101,9 @@ TEST(Promotion) {
} }
TEST(NoPromotion) { HEAP_TEST(NoPromotion) {
CcTest::InitializeVM(); CcTest::InitializeVM();
TestHeap* heap = CcTest::test_heap(); Heap* heap = CcTest::heap();
heap->ConfigureHeap(1, 1, 1, 0); heap->ConfigureHeap(1, 1, 1, 0);
v8::HandleScope sc(CcTest::isolate()); v8::HandleScope sc(CcTest::isolate());
...@@ -125,12 +126,12 @@ TEST(NoPromotion) { ...@@ -125,12 +126,12 @@ TEST(NoPromotion) {
} }
TEST(MarkCompactCollector) { HEAP_TEST(MarkCompactCollector) {
FLAG_incremental_marking = false; FLAG_incremental_marking = false;
FLAG_retain_maps_for_n_gc = 0; FLAG_retain_maps_for_n_gc = 0;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
TestHeap* heap = CcTest::test_heap(); Heap* heap = CcTest::heap();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
v8::HandleScope sc(CcTest::isolate()); v8::HandleScope sc(CcTest::isolate());
...@@ -244,11 +245,11 @@ static void WeakPointerCallback( ...@@ -244,11 +245,11 @@ static void WeakPointerCallback(
} }
TEST(ObjectGroups) { HEAP_TEST(ObjectGroups) {
FLAG_incremental_marking = false; FLAG_incremental_marking = false;
CcTest::InitializeVM(); CcTest::InitializeVM();
GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
TestHeap* heap = CcTest::test_heap(); Heap* heap = CcTest::heap();
NumberOfWeakCalls = 0; NumberOfWeakCalls = 0;
v8::HandleScope handle_scope(CcTest::isolate()); v8::HandleScope handle_scope(CcTest::isolate());
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "src/ic/ic.h" #include "src/ic/ic.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
#include "test/cctest/heap-tester.h"
using namespace v8::base; using namespace v8::base;
using namespace v8::internal; using namespace v8::internal;
...@@ -1402,11 +1403,11 @@ static int LenFromSize(int size) { ...@@ -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. FLAG_max_semi_space_size = 1; // Ensure new space is not growing.
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
TestHeap* heap = CcTest::test_heap(); Heap* heap = CcTest::heap();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment