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
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_;
'gay-fixed.cc',
'gay-precision.cc',
'gay-shortest.cc',
+ 'heap-tester.h',
'print-extension.cc',
'profiler-extension.cc',
'test-accessors.cc',
#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)();
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();
}
--- /dev/null
+// 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_
#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
}
-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();
}
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()));
}
#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;
}
-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);
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);
}
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);
}
}
-THREADED_TEST(ResetWeakHandle) {
- ResetWeakHandle(false);
- ResetWeakHandle(true);
+THREADED_HEAP_TEST(ResetWeakHandle) {
+ v8::internal::HeapTester::ResetWeakHandle(false);
+ v8::internal::HeapTester::ResetWeakHandle(true);
}
#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
}
-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();
}
-TEST(TestSizeOfObjects) {
+HEAP_TEST(TestSizeOfObjects) {
v8::V8::Initialize();
// Get initial heap size after several full GCs, which will stabilize
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()));
}
}
-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());
}
#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;
}
-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());
}
-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());
}
-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());
}
-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());
#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;
}
-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());