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

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

Issue 24169005: remove HEAP from tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-deoptimization.cc ('k') | test/cctest/test-disasm-x64.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 LocalContext context; 43 LocalContext context;
44 Isolate* isolate = CcTest::i_isolate(); 44 Isolate* isolate = CcTest::i_isolate();
45 Factory* factory = isolate->factory(); 45 Factory* factory = isolate->factory();
46 v8::HandleScope scope(context->GetIsolate()); 46 v8::HandleScope scope(context->GetIsolate());
47 Handle<ObjectHashTable> table = factory->NewObjectHashTable(23); 47 Handle<ObjectHashTable> table = factory->NewObjectHashTable(23);
48 Handle<JSObject> a = factory->NewJSArray(7); 48 Handle<JSObject> a = factory->NewJSArray(7);
49 Handle<JSObject> b = factory->NewJSArray(11); 49 Handle<JSObject> b = factory->NewJSArray(11);
50 table = PutIntoObjectHashTable(table, a, b); 50 table = PutIntoObjectHashTable(table, a, b);
51 CHECK_EQ(table->NumberOfElements(), 1); 51 CHECK_EQ(table->NumberOfElements(), 1);
52 CHECK_EQ(table->Lookup(*a), *b); 52 CHECK_EQ(table->Lookup(*a), *b);
53 CHECK_EQ(table->Lookup(*b), HEAP->the_hole_value()); 53 CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value());
54 54
55 // Keys still have to be valid after objects were moved. 55 // Keys still have to be valid after objects were moved.
56 HEAP->CollectGarbage(NEW_SPACE); 56 CcTest::heap()->CollectGarbage(NEW_SPACE);
57 CHECK_EQ(table->NumberOfElements(), 1); 57 CHECK_EQ(table->NumberOfElements(), 1);
58 CHECK_EQ(table->Lookup(*a), *b); 58 CHECK_EQ(table->Lookup(*a), *b);
59 CHECK_EQ(table->Lookup(*b), HEAP->the_hole_value()); 59 CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value());
60 60
61 // Keys that are overwritten should not change number of elements. 61 // Keys that are overwritten should not change number of elements.
62 table = PutIntoObjectHashTable(table, a, factory->NewJSArray(13)); 62 table = PutIntoObjectHashTable(table, a, factory->NewJSArray(13));
63 CHECK_EQ(table->NumberOfElements(), 1); 63 CHECK_EQ(table->NumberOfElements(), 1);
64 CHECK_NE(table->Lookup(*a), *b); 64 CHECK_NE(table->Lookup(*a), *b);
65 65
66 // Keys mapped to the hole should be removed permanently. 66 // Keys mapped to the hole should be removed permanently.
67 table = PutIntoObjectHashTable(table, a, factory->the_hole_value()); 67 table = PutIntoObjectHashTable(table, a, factory->the_hole_value());
68 CHECK_EQ(table->NumberOfElements(), 0); 68 CHECK_EQ(table->NumberOfElements(), 0);
69 CHECK_EQ(table->NumberOfDeletedElements(), 1); 69 CHECK_EQ(table->NumberOfDeletedElements(), 1);
70 CHECK_EQ(table->Lookup(*a), HEAP->the_hole_value()); 70 CHECK_EQ(table->Lookup(*a), CcTest::heap()->the_hole_value());
71 71
72 // Keys should map back to their respective values and also should get 72 // Keys should map back to their respective values and also should get
73 // an identity hash code generated. 73 // an identity hash code generated.
74 for (int i = 0; i < 100; i++) { 74 for (int i = 0; i < 100; i++) {
75 Handle<JSReceiver> key = factory->NewJSArray(7); 75 Handle<JSReceiver> key = factory->NewJSArray(7);
76 Handle<JSObject> value = factory->NewJSArray(11); 76 Handle<JSObject> value = factory->NewJSArray(11);
77 table = PutIntoObjectHashTable(table, key, value); 77 table = PutIntoObjectHashTable(table, key, value);
78 CHECK_EQ(table->NumberOfElements(), i + 1); 78 CHECK_EQ(table->NumberOfElements(), i + 1);
79 CHECK_NE(table->FindEntry(*key), ObjectHashTable::kNotFound); 79 CHECK_NE(table->FindEntry(*key), ObjectHashTable::kNotFound);
80 CHECK_EQ(table->Lookup(*key), *value); 80 CHECK_EQ(table->Lookup(*key), *value);
81 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi()); 81 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi());
82 } 82 }
83 83
84 // Keys never added to the map which already have an identity hash 84 // Keys never added to the map which already have an identity hash
85 // code should not be found. 85 // code should not be found.
86 for (int i = 0; i < 100; i++) { 86 for (int i = 0; i < 100; i++) {
87 Handle<JSReceiver> key = factory->NewJSArray(7); 87 Handle<JSReceiver> key = factory->NewJSArray(7);
88 CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi()); 88 CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi());
89 CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound); 89 CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound);
90 CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); 90 CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value());
91 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi()); 91 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi());
92 } 92 }
93 93
94 // Keys that don't have an identity hash should not be found and also 94 // Keys that don't have an identity hash should not be found and also
95 // should not get an identity hash code generated. 95 // should not get an identity hash code generated.
96 for (int i = 0; i < 100; i++) { 96 for (int i = 0; i < 100; i++) {
97 Handle<JSReceiver> key = factory->NewJSArray(7); 97 Handle<JSReceiver> key = factory->NewJSArray(7);
98 CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); 98 CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value());
99 CHECK_EQ(key->GetIdentityHash(OMIT_CREATION), HEAP->undefined_value()); 99 CHECK_EQ(key->GetIdentityHash(OMIT_CREATION),
100 CcTest::heap()->undefined_value());
100 } 101 }
101 } 102 }
102 103
103 104
104 class ObjectHashTableTest: public ObjectHashTable { 105 class ObjectHashTableTest: public ObjectHashTable {
105 public: 106 public:
106 void insert(int entry, int key, int value) { 107 void insert(int entry, int key, int value) {
107 set(EntryToIndex(entry), Smi::FromInt(key)); 108 set(EntryToIndex(entry), Smi::FromInt(key));
108 set(EntryToIndex(entry) + 1, Smi::FromInt(value)); 109 set(EntryToIndex(entry) + 1, Smi::FromInt(value));
109 } 110 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 Handle<JSObject> key = factory->NewJSArray(0); 164 Handle<JSObject> key = factory->NewJSArray(0);
164 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); 165 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key);
165 166
166 // Force allocation of hash table backing store for hidden properties. 167 // Force allocation of hash table backing store for hidden properties.
167 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); 168 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1"));
168 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); 169 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2"));
169 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); 170 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3"));
170 171
171 // Simulate a full heap so that generating an identity hash code 172 // Simulate a full heap so that generating an identity hash code
172 // in subsequent calls will request GC. 173 // in subsequent calls will request GC.
173 SimulateFullSpace(HEAP->new_space()); 174 SimulateFullSpace(CcTest::heap()->new_space());
174 SimulateFullSpace(HEAP->old_pointer_space()); 175 SimulateFullSpace(CcTest::heap()->old_pointer_space());
175 176
176 // Calling Contains() should not cause GC ever. 177 // Calling Contains() should not cause GC ever.
177 CHECK(!table->Contains(*key)); 178 CHECK(!table->Contains(*key));
178 179
179 // Calling Remove() should not cause GC ever. 180 // Calling Remove() should not cause GC ever.
180 CHECK(!table->Remove(*key)->IsFailure()); 181 CHECK(!table->Remove(*key)->IsFailure());
181 182
182 // Calling Add() should request GC by returning a failure. 183 // Calling Add() should request GC by returning a failure.
183 CHECK(table->Add(*key)->IsRetryAfterGC()); 184 CHECK(table->Add(*key)->IsRetryAfterGC());
184 } 185 }
(...skipping 11 matching lines...) Expand all
196 Handle<JSObject> key = factory->NewJSArray(0); 197 Handle<JSObject> key = factory->NewJSArray(0);
197 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); 198 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key);
198 199
199 // Force allocation of hash table backing store for hidden properties. 200 // Force allocation of hash table backing store for hidden properties.
200 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); 201 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1"));
201 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); 202 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2"));
202 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); 203 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3"));
203 204
204 // Simulate a full heap so that generating an identity hash code 205 // Simulate a full heap so that generating an identity hash code
205 // in subsequent calls will request GC. 206 // in subsequent calls will request GC.
206 SimulateFullSpace(HEAP->new_space()); 207 SimulateFullSpace(CcTest::heap()->new_space());
207 SimulateFullSpace(HEAP->old_pointer_space()); 208 SimulateFullSpace(CcTest::heap()->old_pointer_space());
208 209
209 // Calling Lookup() should not cause GC ever. 210 // Calling Lookup() should not cause GC ever.
210 CHECK(table->Lookup(*key)->IsTheHole()); 211 CHECK(table->Lookup(*key)->IsTheHole());
211 212
212 // Calling Put() should request GC by returning a failure. 213 // Calling Put() should request GC by returning a failure.
213 CHECK(table->Put(*key, *key)->IsRetryAfterGC()); 214 CHECK(table->Put(*key, *key)->IsRetryAfterGC());
214 } 215 }
215 #endif 216 #endif
OLDNEW
« no previous file with comments | « test/cctest/test-deoptimization.cc ('k') | test/cctest/test-disasm-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698