OLD | NEW |
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 CHECK_EQ(key->GetIdentityHash(), | 99 CHECK_EQ(key->GetIdentityHash(), |
100 CcTest::heap()->undefined_value()); | 100 CcTest::heap()->undefined_value()); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 TEST(HashMap) { | 105 TEST(HashMap) { |
106 LocalContext context; | 106 LocalContext context; |
107 v8::HandleScope scope(context->GetIsolate()); | 107 v8::HandleScope scope(context->GetIsolate()); |
108 Isolate* isolate = CcTest::i_isolate(); | 108 Isolate* isolate = CcTest::i_isolate(); |
109 TestHashMap(isolate->factory()->NewObjectHashTable(23)); | 109 TestHashMap(ObjectHashTable::New(isolate, 23)); |
110 TestHashMap(isolate->factory()->NewOrderedHashMap()); | 110 TestHashMap(isolate->factory()->NewOrderedHashMap()); |
111 } | 111 } |
112 | 112 |
113 | 113 |
114 class ObjectHashTableTest: public ObjectHashTable { | 114 class ObjectHashTableTest: public ObjectHashTable { |
115 public: | 115 public: |
116 void insert(int entry, int key, int value) { | 116 void insert(int entry, int key, int value) { |
117 set(EntryToIndex(entry), Smi::FromInt(key)); | 117 set(EntryToIndex(entry), Smi::FromInt(key)); |
118 set(EntryToIndex(entry) + 1, Smi::FromInt(value)); | 118 set(EntryToIndex(entry) + 1, Smi::FromInt(value)); |
119 } | 119 } |
120 | 120 |
121 int lookup(int key) { | 121 int lookup(int key) { |
122 return Smi::cast(Lookup(Smi::FromInt(key)))->value(); | 122 return Smi::cast(Lookup(Smi::FromInt(key)))->value(); |
123 } | 123 } |
124 | 124 |
125 int capacity() { | 125 int capacity() { |
126 return Capacity(); | 126 return Capacity(); |
127 } | 127 } |
128 }; | 128 }; |
129 | 129 |
130 | 130 |
131 TEST(HashTableRehash) { | 131 TEST(HashTableRehash) { |
132 LocalContext context; | 132 LocalContext context; |
133 Isolate* isolate = CcTest::i_isolate(); | 133 Isolate* isolate = CcTest::i_isolate(); |
134 Factory* factory = isolate->factory(); | |
135 v8::HandleScope scope(context->GetIsolate()); | 134 v8::HandleScope scope(context->GetIsolate()); |
136 // Test almost filled table. | 135 // Test almost filled table. |
137 { | 136 { |
138 Handle<ObjectHashTable> table = factory->NewObjectHashTable(100); | 137 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 100); |
139 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); | 138 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); |
140 int capacity = t->capacity(); | 139 int capacity = t->capacity(); |
141 for (int i = 0; i < capacity - 1; i++) { | 140 for (int i = 0; i < capacity - 1; i++) { |
142 t->insert(i, i * i, i); | 141 t->insert(i, i * i, i); |
143 } | 142 } |
144 t->Rehash(Smi::FromInt(0)); | 143 t->Rehash(Smi::FromInt(0)); |
145 for (int i = 0; i < capacity - 1; i++) { | 144 for (int i = 0; i < capacity - 1; i++) { |
146 CHECK_EQ(i, t->lookup(i * i)); | 145 CHECK_EQ(i, t->lookup(i * i)); |
147 } | 146 } |
148 } | 147 } |
149 // Test half-filled table. | 148 // Test half-filled table. |
150 { | 149 { |
151 Handle<ObjectHashTable> table = factory->NewObjectHashTable(100); | 150 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 100); |
152 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); | 151 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); |
153 int capacity = t->capacity(); | 152 int capacity = t->capacity(); |
154 for (int i = 0; i < capacity / 2; i++) { | 153 for (int i = 0; i < capacity / 2; i++) { |
155 t->insert(i, i * i, i); | 154 t->insert(i, i * i, i); |
156 } | 155 } |
157 t->Rehash(Smi::FromInt(0)); | 156 t->Rehash(Smi::FromInt(0)); |
158 for (int i = 0; i < capacity / 2; i++) { | 157 for (int i = 0; i < capacity / 2; i++) { |
159 CHECK_EQ(i, t->lookup(i * i)); | 158 CHECK_EQ(i, t->lookup(i * i)); |
160 } | 159 } |
161 } | 160 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 HashMap::Put(table, key, key); | 232 HashMap::Put(table, key, key); |
234 CHECK(gc_count < isolate->heap()->gc_count()); | 233 CHECK(gc_count < isolate->heap()->gc_count()); |
235 } | 234 } |
236 | 235 |
237 | 236 |
238 TEST(ObjectHashTableCausesGC) { | 237 TEST(ObjectHashTableCausesGC) { |
239 i::FLAG_stress_compaction = false; | 238 i::FLAG_stress_compaction = false; |
240 LocalContext context; | 239 LocalContext context; |
241 v8::HandleScope scope(context->GetIsolate()); | 240 v8::HandleScope scope(context->GetIsolate()); |
242 Isolate* isolate = CcTest::i_isolate(); | 241 Isolate* isolate = CcTest::i_isolate(); |
243 TestHashMapCausesGC(isolate->factory()->NewObjectHashTable(1)); | 242 TestHashMapCausesGC(ObjectHashTable::New(isolate, 1)); |
244 TestHashMapCausesGC(isolate->factory()->NewOrderedHashMap()); | 243 TestHashMapCausesGC(isolate->factory()->NewOrderedHashMap()); |
245 } | 244 } |
246 #endif | 245 #endif |
247 | 246 |
248 | 247 |
249 } | 248 } |
OLD | NEW |