Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/cctest/test-heap.cc

Issue 1293283003: [heap,cctest] Get rid of protected-for-sake-of-testing scope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add heap-tester.h to cctest.gyp Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 #include "src/context-measure.h" 32 #include "src/context-measure.h"
33 #include "src/deoptimizer.h" 33 #include "src/deoptimizer.h"
34 #include "src/execution.h" 34 #include "src/execution.h"
35 #include "src/factory.h" 35 #include "src/factory.h"
36 #include "src/global-handles.h" 36 #include "src/global-handles.h"
37 #include "src/heap/gc-tracer.h" 37 #include "src/heap/gc-tracer.h"
38 #include "src/ic/ic.h" 38 #include "src/ic/ic.h"
39 #include "src/macro-assembler.h" 39 #include "src/macro-assembler.h"
40 #include "src/snapshot/snapshot.h" 40 #include "src/snapshot/snapshot.h"
41 #include "test/cctest/cctest.h" 41 #include "test/cctest/cctest.h"
42 #include "test/cctest/heap-tester.h"
42 43
43 using v8::Just; 44 using v8::Just;
44 45
45 namespace v8 { 46 namespace v8 {
46 namespace internal { 47 namespace internal {
47 48
48 // Tests that should have access to private methods of {v8::internal::Heap}.
49 // Those tests need to be defined using HEAP_TEST(Name) { ... }.
50 #define HEAP_TEST_METHODS(V) \
51 V(GCFlags)
52
53
54 #define HEAP_TEST(Name) \
55 CcTest register_test_##Name(HeapTester::Test##Name, __FILE__, #Name, NULL, \
56 true, true); \
57 void HeapTester::Test##Name()
58
59
60 class HeapTester {
61 public:
62 #define DECLARE_STATIC(Name) static void Test##Name();
63
64 HEAP_TEST_METHODS(DECLARE_STATIC)
65 #undef HEAP_TEST_METHODS
66 };
67
68
69 static void CheckMap(Map* map, int type, int instance_size) { 49 static void CheckMap(Map* map, int type, int instance_size) {
70 CHECK(map->IsHeapObject()); 50 CHECK(map->IsHeapObject());
71 #ifdef DEBUG 51 #ifdef DEBUG
72 CHECK(CcTest::heap()->Contains(map)); 52 CHECK(CcTest::heap()->Contains(map));
73 #endif 53 #endif
74 CHECK_EQ(CcTest::heap()->meta_map(), map->map()); 54 CHECK_EQ(CcTest::heap()->meta_map(), map->map());
75 CHECK_EQ(type, map->instance_type()); 55 CHECK_EQ(type, map->instance_type());
76 CHECK_EQ(instance_size, map->instance_size()); 56 CHECK_EQ(instance_size, map->instance_size());
77 } 57 }
78 58
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 CHECK_EQ(objs_count, next_objs_index); 1121 CHECK_EQ(objs_count, next_objs_index);
1142 CHECK_EQ(objs_count, ObjectsFoundInHeap(CcTest::heap(), objs, objs_count)); 1122 CHECK_EQ(objs_count, ObjectsFoundInHeap(CcTest::heap(), objs, objs_count));
1143 } 1123 }
1144 1124
1145 1125
1146 static int LenFromSize(int size) { 1126 static int LenFromSize(int size) {
1147 return (size - FixedArray::kHeaderSize) / kPointerSize; 1127 return (size - FixedArray::kHeaderSize) / kPointerSize;
1148 } 1128 }
1149 1129
1150 1130
1151 TEST(Regression39128) { 1131 HEAP_TEST(Regression39128) {
1152 // Test case for crbug.com/39128. 1132 // Test case for crbug.com/39128.
1153 CcTest::InitializeVM(); 1133 CcTest::InitializeVM();
1154 Isolate* isolate = CcTest::i_isolate(); 1134 Isolate* isolate = CcTest::i_isolate();
1155 TestHeap* heap = CcTest::test_heap(); 1135 Heap* heap = CcTest::heap();
1156 1136
1157 // Increase the chance of 'bump-the-pointer' allocation in old space. 1137 // Increase the chance of 'bump-the-pointer' allocation in old space.
1158 heap->CollectAllGarbage(); 1138 heap->CollectAllGarbage();
1159 1139
1160 v8::HandleScope scope(CcTest::isolate()); 1140 v8::HandleScope scope(CcTest::isolate());
1161 1141
1162 // The plan: create JSObject which references objects in new space. 1142 // The plan: create JSObject which references objects in new space.
1163 // Then clone this object (forcing it to go into old space) and check 1143 // Then clone this object (forcing it to go into old space) and check
1164 // that region dirty marks are updated correctly. 1144 // that region dirty marks are updated correctly.
1165 1145
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 CHECK_LE(size_of_regexp_code, 1 * MB); 1925 CHECK_LE(size_of_regexp_code, 1 * MB);
1946 } 1926 }
1947 1927
1948 // Small regexp is half the size, but compiles to more than twice the code 1928 // Small regexp is half the size, but compiles to more than twice the code
1949 // due to the optimization steps. 1929 // due to the optimization steps.
1950 CHECK_GE(size_with_optimized_regexp, 1930 CHECK_GE(size_with_optimized_regexp,
1951 size_with_regexp + size_of_regexp_code * 2); 1931 size_with_regexp + size_of_regexp_code * 2);
1952 } 1932 }
1953 1933
1954 1934
1955 TEST(TestSizeOfObjects) { 1935 HEAP_TEST(TestSizeOfObjects) {
1956 v8::V8::Initialize(); 1936 v8::V8::Initialize();
1957 1937
1958 // Get initial heap size after several full GCs, which will stabilize 1938 // Get initial heap size after several full GCs, which will stabilize
1959 // the heap size and return with sweeping finished completely. 1939 // the heap size and return with sweeping finished completely.
1960 CcTest::heap()->CollectAllGarbage(); 1940 CcTest::heap()->CollectAllGarbage();
1961 CcTest::heap()->CollectAllGarbage(); 1941 CcTest::heap()->CollectAllGarbage();
1962 CcTest::heap()->CollectAllGarbage(); 1942 CcTest::heap()->CollectAllGarbage();
1963 CcTest::heap()->CollectAllGarbage(); 1943 CcTest::heap()->CollectAllGarbage();
1964 CcTest::heap()->CollectAllGarbage(); 1944 CcTest::heap()->CollectAllGarbage();
1965 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); 1945 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
1966 if (collector->sweeping_in_progress()) { 1946 if (collector->sweeping_in_progress()) {
1967 collector->EnsureSweepingCompleted(); 1947 collector->EnsureSweepingCompleted();
1968 } 1948 }
1969 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); 1949 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects());
1970 1950
1971 { 1951 {
1972 // Allocate objects on several different old-space pages so that 1952 // Allocate objects on several different old-space pages so that
1973 // concurrent sweeper threads will be busy sweeping the old space on 1953 // concurrent sweeper threads will be busy sweeping the old space on
1974 // subsequent GC runs. 1954 // subsequent GC runs.
1975 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 1955 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
1976 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); 1956 int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
1977 for (int i = 1; i <= 100; i++) { 1957 for (int i = 1; i <= 100; i++) {
1978 CcTest::test_heap()->AllocateFixedArray(8192, TENURED).ToObjectChecked(); 1958 CcTest::heap()->AllocateFixedArray(8192, TENURED).ToObjectChecked();
1979 CHECK_EQ(initial_size + i * filler_size, 1959 CHECK_EQ(initial_size + i * filler_size,
1980 static_cast<int>(CcTest::heap()->SizeOfObjects())); 1960 static_cast<int>(CcTest::heap()->SizeOfObjects()));
1981 } 1961 }
1982 } 1962 }
1983 1963
1984 // The heap size should go back to initial size after a full GC, even 1964 // The heap size should go back to initial size after a full GC, even
1985 // though sweeping didn't finish yet. 1965 // though sweeping didn't finish yet.
1986 CcTest::heap()->CollectAllGarbage(); 1966 CcTest::heap()->CollectAllGarbage();
1987 1967
1988 // Normally sweeping would not be complete here, but no guarantees. 1968 // Normally sweeping would not be complete here, but no guarantees.
(...skipping 3828 matching lines...) Expand 10 before | Expand all | Expand 10 after
5817 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); 5797 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
5818 Handle<JSArray> array = factory->NewJSArray(2); 5798 Handle<JSArray> array = factory->NewJSArray(2);
5819 5799
5820 Handle<String> name = factory->InternalizeUtf8String("testArray"); 5800 Handle<String> name = factory->InternalizeUtf8String("testArray");
5821 JSReceiver::SetProperty(global, name, array, SLOPPY).Check(); 5801 JSReceiver::SetProperty(global, name, array, SLOPPY).Check();
5822 CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();"); 5802 CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();");
5823 heap->CollectGarbage(OLD_SPACE); 5803 heap->CollectGarbage(OLD_SPACE);
5824 } 5804 }
5825 5805
5826 5806
5827 TEST(NumberStringCacheSize) { 5807 HEAP_TEST(NumberStringCacheSize) {
5828 // Test that the number-string cache has not been resized in the snapshot. 5808 // Test that the number-string cache has not been resized in the snapshot.
5829 CcTest::InitializeVM(); 5809 CcTest::InitializeVM();
5830 Isolate* isolate = CcTest::i_isolate(); 5810 Isolate* isolate = CcTest::i_isolate();
5831 if (!isolate->snapshot_available()) return; 5811 if (!isolate->snapshot_available()) return;
5832 Heap* heap = isolate->heap(); 5812 Heap* heap = isolate->heap();
5833 CHECK_EQ(TestHeap::kInitialNumberStringCacheSize * 2, 5813 CHECK_EQ(Heap::kInitialNumberStringCacheSize * 2,
5834 heap->number_string_cache()->length()); 5814 heap->number_string_cache()->length());
5835 } 5815 }
5836 5816
5837 5817
5838 TEST(Regress3877) { 5818 TEST(Regress3877) {
5839 CcTest::InitializeVM(); 5819 CcTest::InitializeVM();
5840 Isolate* isolate = CcTest::i_isolate(); 5820 Isolate* isolate = CcTest::i_isolate();
5841 Heap* heap = isolate->heap(); 5821 Heap* heap = isolate->heap();
5842 Factory* factory = isolate->factory(); 5822 Factory* factory = isolate->factory();
5843 HandleScope scope(isolate); 5823 HandleScope scope(isolate);
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
6498 { 6478 {
6499 SharedFunctionInfo::Iterator iterator(isolate); 6479 SharedFunctionInfo::Iterator iterator(isolate);
6500 while (iterator.Next()) sfi_count--; 6480 while (iterator.Next()) sfi_count--;
6501 } 6481 }
6502 6482
6503 CHECK_EQ(0, sfi_count); 6483 CHECK_EQ(0, sfi_count);
6504 } 6484 }
6505 6485
6506 } // namespace internal 6486 } // namespace internal
6507 } // namespace v8 6487 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698