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

Side by Side Diff: test/cctest/test-unboxed-doubles.cc

Issue 2310143002: [heap] Introduce enum of garbage collection reasons. (Closed)
Patch Set: rebase Created 4 years, 3 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-symbols.cc ('k') | test/cctest/test-weakmaps.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/compilation-cache.h" 10 #include "src/compilation-cache.h"
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 CHECK(object->HasFastProperties()); 927 CHECK(object->HasFastProperties());
928 CHECK(!object->map()->HasFastPointerLayout()); 928 CHECK(!object->map()->HasFastPointerLayout());
929 929
930 Handle<Map> normalized_map = 930 Handle<Map> normalized_map =
931 Map::Normalize(map, KEEP_INOBJECT_PROPERTIES, "testing"); 931 Map::Normalize(map, KEEP_INOBJECT_PROPERTIES, "testing");
932 JSObject::MigrateToMap(object, normalized_map); 932 JSObject::MigrateToMap(object, normalized_map);
933 CHECK(!object->HasFastProperties()); 933 CHECK(!object->HasFastProperties());
934 CHECK(object->map()->HasFastPointerLayout()); 934 CHECK(object->map()->HasFastPointerLayout());
935 935
936 // Trigger GCs and heap verification. 936 // Trigger GCs and heap verification.
937 CcTest::heap()->CollectAllGarbage(); 937 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
938 } 938 }
939 939
940 940
941 TEST(DescriptorArrayTrimming) { 941 TEST(DescriptorArrayTrimming) {
942 CcTest::InitializeVM(); 942 CcTest::InitializeVM();
943 v8::HandleScope scope(CcTest::isolate()); 943 v8::HandleScope scope(CcTest::isolate());
944 Isolate* isolate = CcTest::i_isolate(); 944 Isolate* isolate = CcTest::i_isolate();
945 945
946 const int kFieldCount = 128; 946 const int kFieldCount = 128;
947 const int kSplitFieldIndex = 32; 947 const int kSplitFieldIndex = 32;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 // The unused tail of the layout descriptor is now "durty" because of sharing. 984 // The unused tail of the layout descriptor is now "durty" because of sharing.
985 CHECK(map->layout_descriptor()->IsConsistentWithMap(*map)); 985 CHECK(map->layout_descriptor()->IsConsistentWithMap(*map));
986 for (int i = kSplitFieldIndex + 1; i < kTrimmedLayoutDescriptorLength; i++) { 986 for (int i = kSplitFieldIndex + 1; i < kTrimmedLayoutDescriptorLength; i++) {
987 CHECK(!map->layout_descriptor()->IsTagged(i)); 987 CHECK(!map->layout_descriptor()->IsTagged(i));
988 } 988 }
989 CHECK_LT(map->NumberOfOwnDescriptors(), 989 CHECK_LT(map->NumberOfOwnDescriptors(),
990 map->instance_descriptors()->number_of_descriptors()); 990 map->instance_descriptors()->number_of_descriptors());
991 991
992 // Call GC that should trim both |map|'s descriptor array and layout 992 // Call GC that should trim both |map|'s descriptor array and layout
993 // descriptor. 993 // descriptor.
994 CcTest::heap()->CollectAllGarbage(); 994 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
995 995
996 // The unused tail of the layout descriptor is now "clean" again. 996 // The unused tail of the layout descriptor is now "clean" again.
997 CHECK(map->layout_descriptor()->IsConsistentWithMap(*map, true)); 997 CHECK(map->layout_descriptor()->IsConsistentWithMap(*map, true));
998 CHECK(map->owns_descriptors()); 998 CHECK(map->owns_descriptors());
999 CHECK_EQ(map->NumberOfOwnDescriptors(), 999 CHECK_EQ(map->NumberOfOwnDescriptors(),
1000 map->instance_descriptors()->number_of_descriptors()); 1000 map->instance_descriptors()->number_of_descriptors());
1001 CHECK(map->layout_descriptor()->IsSlowLayout()); 1001 CHECK(map->layout_descriptor()->IsSlowLayout());
1002 CHECK_EQ(2, map->layout_descriptor()->length()); 1002 CHECK_EQ(2, map->layout_descriptor()->length());
1003 1003
1004 { 1004 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 { 1050 {
1051 // Ensure the object is properly set up. 1051 // Ensure the object is properly set up.
1052 FieldIndex field_index = FieldIndex::ForDescriptor(*map, 0); 1052 FieldIndex field_index = FieldIndex::ForDescriptor(*map, 0);
1053 CHECK(field_index.is_inobject() && field_index.is_double()); 1053 CHECK(field_index.is_inobject() && field_index.is_double());
1054 CHECK_EQ(FLAG_unbox_double_fields, map->IsUnboxedDoubleField(field_index)); 1054 CHECK_EQ(FLAG_unbox_double_fields, map->IsUnboxedDoubleField(field_index));
1055 CHECK_EQ(42.5, GetDoubleFieldValue(*obj, field_index)); 1055 CHECK_EQ(42.5, GetDoubleFieldValue(*obj, field_index));
1056 } 1056 }
1057 CHECK(isolate->heap()->new_space()->Contains(*obj)); 1057 CHECK(isolate->heap()->new_space()->Contains(*obj));
1058 1058
1059 // Do scavenge so that |obj| is moved to survivor space. 1059 // Do scavenge so that |obj| is moved to survivor space.
1060 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 1060 CcTest::CollectGarbage(i::NEW_SPACE);
1061 1061
1062 // Create temp object in the new space. 1062 // Create temp object in the new space.
1063 Handle<JSArray> temp = factory->NewJSArray(0, FAST_ELEMENTS); 1063 Handle<JSArray> temp = factory->NewJSArray(0, FAST_ELEMENTS);
1064 CHECK(isolate->heap()->new_space()->Contains(*temp)); 1064 CHECK(isolate->heap()->new_space()->Contains(*temp));
1065 1065
1066 // Construct a double value that looks like a pointer to the new space object 1066 // Construct a double value that looks like a pointer to the new space object
1067 // and store it into the obj. 1067 // and store it into the obj.
1068 Address fake_object = reinterpret_cast<Address>(*temp) + kPointerSize; 1068 Address fake_object = reinterpret_cast<Address>(*temp) + kPointerSize;
1069 double boom_value = bit_cast<double>(fake_object); 1069 double boom_value = bit_cast<double>(fake_object);
1070 1070
1071 FieldIndex field_index = FieldIndex::ForDescriptor(obj->map(), 0); 1071 FieldIndex field_index = FieldIndex::ForDescriptor(obj->map(), 0);
1072 Handle<HeapNumber> boom_number = factory->NewHeapNumber(boom_value, MUTABLE); 1072 Handle<HeapNumber> boom_number = factory->NewHeapNumber(boom_value, MUTABLE);
1073 obj->FastPropertyAtPut(field_index, *boom_number); 1073 obj->FastPropertyAtPut(field_index, *boom_number);
1074 1074
1075 // Now |obj| moves to old gen and it has a double field that looks like 1075 // Now |obj| moves to old gen and it has a double field that looks like
1076 // a pointer to a from semi-space. 1076 // a pointer to a from semi-space.
1077 CcTest::heap()->CollectGarbage(i::NEW_SPACE, "boom"); 1077 CcTest::CollectGarbage(i::NEW_SPACE);
1078 1078
1079 CHECK(isolate->heap()->old_space()->Contains(*obj)); 1079 CHECK(isolate->heap()->old_space()->Contains(*obj));
1080 1080
1081 CHECK_EQ(boom_value, GetDoubleFieldValue(*obj, field_index)); 1081 CHECK_EQ(boom_value, GetDoubleFieldValue(*obj, field_index));
1082 } 1082 }
1083 1083
1084 1084
1085 TEST(DoScavengeWithIncrementalWriteBarrier) { 1085 TEST(DoScavengeWithIncrementalWriteBarrier) {
1086 if (FLAG_never_compact || !FLAG_incremental_marking) return; 1086 if (FLAG_never_compact || !FLAG_incremental_marking) return;
1087 CcTest::InitializeVM(); 1087 CcTest::InitializeVM();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 1148
1149 // Check that everything is ready for triggering incremental write barrier 1149 // Check that everything is ready for triggering incremental write barrier
1150 // during scavenge (i.e. that |obj| is black and incremental marking is 1150 // during scavenge (i.e. that |obj| is black and incremental marking is
1151 // in compacting mode and |obj_value|'s page is an evacuation candidate). 1151 // in compacting mode and |obj_value|'s page is an evacuation candidate).
1152 IncrementalMarking* marking = heap->incremental_marking(); 1152 IncrementalMarking* marking = heap->incremental_marking();
1153 CHECK(marking->IsCompacting()); 1153 CHECK(marking->IsCompacting());
1154 CHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(*obj))); 1154 CHECK(Marking::IsBlack(ObjectMarking::MarkBitFrom(*obj)));
1155 CHECK(MarkCompactCollector::IsOnEvacuationCandidate(*obj_value)); 1155 CHECK(MarkCompactCollector::IsOnEvacuationCandidate(*obj_value));
1156 1156
1157 // Trigger GCs so that |obj| moves to old gen. 1157 // Trigger GCs so that |obj| moves to old gen.
1158 heap->CollectGarbage(i::NEW_SPACE); // in survivor space now 1158 CcTest::CollectGarbage(i::NEW_SPACE); // in survivor space now
1159 heap->CollectGarbage(i::NEW_SPACE); // in old gen now 1159 CcTest::CollectGarbage(i::NEW_SPACE); // in old gen now
1160 1160
1161 CHECK(isolate->heap()->old_space()->Contains(*obj)); 1161 CHECK(isolate->heap()->old_space()->Contains(*obj));
1162 CHECK(isolate->heap()->old_space()->Contains(*obj_value)); 1162 CHECK(isolate->heap()->old_space()->Contains(*obj_value));
1163 CHECK(MarkCompactCollector::IsOnEvacuationCandidate(*obj_value)); 1163 CHECK(MarkCompactCollector::IsOnEvacuationCandidate(*obj_value));
1164 1164
1165 heap->CollectGarbage(i::OLD_SPACE, "boom"); 1165 CcTest::CollectGarbage(i::OLD_SPACE);
1166 1166
1167 // |obj_value| must be evacuated. 1167 // |obj_value| must be evacuated.
1168 CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(*obj_value)); 1168 CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(*obj_value));
1169 1169
1170 FieldIndex field_index = FieldIndex::ForDescriptor(*map, 1); 1170 FieldIndex field_index = FieldIndex::ForDescriptor(*map, 1);
1171 CHECK_EQ(*obj_value, obj->RawFastPropertyAt(field_index)); 1171 CHECK_EQ(*obj_value, obj->RawFastPropertyAt(field_index));
1172 } 1172 }
1173 1173
1174 1174
1175 static void TestLayoutDescriptorHelper(Isolate* isolate, 1175 static void TestLayoutDescriptorHelper(Isolate* isolate,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 1405
1406 Address fake_object = reinterpret_cast<Address>(*obj_value) + kPointerSize; 1406 Address fake_object = reinterpret_cast<Address>(*obj_value) + kPointerSize;
1407 double boom_value = bit_cast<double>(fake_object); 1407 double boom_value = bit_cast<double>(fake_object);
1408 1408
1409 FieldIndex double_field_index = 1409 FieldIndex double_field_index =
1410 FieldIndex::ForDescriptor(*new_map, double_descriptor); 1410 FieldIndex::ForDescriptor(*new_map, double_descriptor);
1411 CHECK(obj->IsUnboxedDoubleField(double_field_index)); 1411 CHECK(obj->IsUnboxedDoubleField(double_field_index));
1412 obj->RawFastDoublePropertyAtPut(double_field_index, boom_value); 1412 obj->RawFastDoublePropertyAtPut(double_field_index, boom_value);
1413 1413
1414 // Trigger GC to evacuate all candidates. 1414 // Trigger GC to evacuate all candidates.
1415 CcTest::heap()->CollectGarbage(NEW_SPACE, "boom"); 1415 CcTest::CollectGarbage(NEW_SPACE);
1416 1416
1417 if (check_tagged_value) { 1417 if (check_tagged_value) {
1418 FieldIndex tagged_field_index = 1418 FieldIndex tagged_field_index =
1419 FieldIndex::ForDescriptor(*new_map, tagged_descriptor); 1419 FieldIndex::ForDescriptor(*new_map, tagged_descriptor);
1420 CHECK_EQ(*obj_value, obj->RawFastPropertyAt(tagged_field_index)); 1420 CHECK_EQ(*obj_value, obj->RawFastPropertyAt(tagged_field_index));
1421 } 1421 }
1422 CHECK_EQ(boom_value, obj->RawFastDoublePropertyAt(double_field_index)); 1422 CHECK_EQ(boom_value, obj->RawFastDoublePropertyAt(double_field_index));
1423 } 1423 }
1424 1424
1425 1425
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 JSObject::MigrateToMap(obj, new_map); 1484 JSObject::MigrateToMap(obj, new_map);
1485 1485
1486 double boom_value = bit_cast<double>(UINT64_C(0xbaad0176a37c28e1)); 1486 double boom_value = bit_cast<double>(UINT64_C(0xbaad0176a37c28e1));
1487 1487
1488 FieldIndex double_field_index = 1488 FieldIndex double_field_index =
1489 FieldIndex::ForDescriptor(*new_map, double_descriptor); 1489 FieldIndex::ForDescriptor(*new_map, double_descriptor);
1490 CHECK(obj->IsUnboxedDoubleField(double_field_index)); 1490 CHECK(obj->IsUnboxedDoubleField(double_field_index));
1491 obj->RawFastDoublePropertyAtPut(double_field_index, boom_value); 1491 obj->RawFastDoublePropertyAtPut(double_field_index, boom_value);
1492 1492
1493 // Trigger GC to evacuate all candidates. 1493 // Trigger GC to evacuate all candidates.
1494 CcTest::heap()->CollectGarbage(OLD_SPACE, "boom"); 1494 CcTest::CollectGarbage(OLD_SPACE);
1495 1495
1496 // Ensure that the values are still there and correct. 1496 // Ensure that the values are still there and correct.
1497 CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(*obj_value)); 1497 CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(*obj_value));
1498 1498
1499 if (check_tagged_value) { 1499 if (check_tagged_value) {
1500 FieldIndex tagged_field_index = 1500 FieldIndex tagged_field_index =
1501 FieldIndex::ForDescriptor(*new_map, tagged_descriptor); 1501 FieldIndex::ForDescriptor(*new_map, tagged_descriptor);
1502 CHECK_EQ(*obj_value, obj->RawFastPropertyAt(tagged_field_index)); 1502 CHECK_EQ(*obj_value, obj->RawFastPropertyAt(tagged_field_index));
1503 } 1503 }
1504 CHECK_EQ(boom_value, obj->RawFastDoublePropertyAt(double_field_index)); 1504 CHECK_EQ(boom_value, obj->RawFastDoublePropertyAt(double_field_index));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 1554
1555 // TODO(ishell): add respective tests for property kind reconfiguring from 1555 // TODO(ishell): add respective tests for property kind reconfiguring from
1556 // accessor field to double, once accessor fields are supported by 1556 // accessor field to double, once accessor fields are supported by
1557 // Map::ReconfigureProperty(). 1557 // Map::ReconfigureProperty().
1558 1558
1559 1559
1560 // TODO(ishell): add respective tests for fast property removal case once 1560 // TODO(ishell): add respective tests for fast property removal case once
1561 // Map::ReconfigureProperty() supports that. 1561 // Map::ReconfigureProperty() supports that.
1562 1562
1563 #endif 1563 #endif
OLDNEW
« no previous file with comments | « test/cctest/test-symbols.cc ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698