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 23 matching lines...) Expand all Loading... |
34 #include "macro-assembler.h" | 34 #include "macro-assembler.h" |
35 #include "objects.h" | 35 #include "objects.h" |
36 #include "global-handles.h" | 36 #include "global-handles.h" |
37 #include "cctest.h" | 37 #include "cctest.h" |
38 | 38 |
39 using namespace v8::internal; | 39 using namespace v8::internal; |
40 | 40 |
41 | 41 |
42 TEST(ObjectHashTable) { | 42 TEST(ObjectHashTable) { |
43 LocalContext context; | 43 LocalContext context; |
44 Isolate* isolate = Isolate::Current(); | 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), HEAP->the_hole_value()); |
54 | 54 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 | 114 |
115 int capacity() { | 115 int capacity() { |
116 return Capacity(); | 116 return Capacity(); |
117 } | 117 } |
118 }; | 118 }; |
119 | 119 |
120 | 120 |
121 TEST(HashTableRehash) { | 121 TEST(HashTableRehash) { |
122 LocalContext context; | 122 LocalContext context; |
123 Isolate* isolate = Isolate::Current(); | 123 Isolate* isolate = CcTest::i_isolate(); |
124 Factory* factory = isolate->factory(); | 124 Factory* factory = isolate->factory(); |
125 v8::HandleScope scope(context->GetIsolate()); | 125 v8::HandleScope scope(context->GetIsolate()); |
126 // Test almost filled table. | 126 // Test almost filled table. |
127 { | 127 { |
128 Handle<ObjectHashTable> table = factory->NewObjectHashTable(100); | 128 Handle<ObjectHashTable> table = factory->NewObjectHashTable(100); |
129 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); | 129 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); |
130 int capacity = t->capacity(); | 130 int capacity = t->capacity(); |
131 for (int i = 0; i < capacity - 1; i++) { | 131 for (int i = 0; i < capacity - 1; i++) { |
132 t->insert(i, i * i, i); | 132 t->insert(i, i * i, i); |
133 } | 133 } |
(...skipping 15 matching lines...) Expand all Loading... |
149 CHECK_EQ(i, t->lookup(i * i)); | 149 CHECK_EQ(i, t->lookup(i * i)); |
150 } | 150 } |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 #ifdef DEBUG | 155 #ifdef DEBUG |
156 TEST(ObjectHashSetCausesGC) { | 156 TEST(ObjectHashSetCausesGC) { |
157 i::FLAG_stress_compaction = false; | 157 i::FLAG_stress_compaction = false; |
158 LocalContext context; | 158 LocalContext context; |
159 Isolate* isolate = Isolate::Current(); | 159 Isolate* isolate = CcTest::i_isolate(); |
160 Factory* factory = isolate->factory(); | 160 Factory* factory = isolate->factory(); |
161 v8::HandleScope scope(context->GetIsolate()); | 161 v8::HandleScope scope(context->GetIsolate()); |
162 Handle<ObjectHashSet> table = factory->NewObjectHashSet(1); | 162 Handle<ObjectHashSet> table = factory->NewObjectHashSet(1); |
163 Handle<JSObject> key = factory->NewJSArray(0); | 163 Handle<JSObject> key = factory->NewJSArray(0); |
164 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); | 164 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); |
165 | 165 |
166 // Force allocation of hash table backing store for hidden properties. | 166 // Force allocation of hash table backing store for hidden properties. |
167 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); | 167 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); |
168 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); | 168 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); |
169 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); | 169 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); |
(...skipping 12 matching lines...) Expand all Loading... |
182 // Calling Add() should request GC by returning a failure. | 182 // Calling Add() should request GC by returning a failure. |
183 CHECK(table->Add(*key)->IsRetryAfterGC()); | 183 CHECK(table->Add(*key)->IsRetryAfterGC()); |
184 } | 184 } |
185 #endif | 185 #endif |
186 | 186 |
187 | 187 |
188 #ifdef DEBUG | 188 #ifdef DEBUG |
189 TEST(ObjectHashTableCausesGC) { | 189 TEST(ObjectHashTableCausesGC) { |
190 i::FLAG_stress_compaction = false; | 190 i::FLAG_stress_compaction = false; |
191 LocalContext context; | 191 LocalContext context; |
192 Isolate* isolate = Isolate::Current(); | 192 Isolate* isolate = CcTest::i_isolate(); |
193 Factory* factory = isolate->factory(); | 193 Factory* factory = isolate->factory(); |
194 v8::HandleScope scope(context->GetIsolate()); | 194 v8::HandleScope scope(context->GetIsolate()); |
195 Handle<ObjectHashTable> table = factory->NewObjectHashTable(1); | 195 Handle<ObjectHashTable> table = factory->NewObjectHashTable(1); |
196 Handle<JSObject> key = factory->NewJSArray(0); | 196 Handle<JSObject> key = factory->NewJSArray(0); |
197 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); | 197 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); |
198 | 198 |
199 // Force allocation of hash table backing store for hidden properties. | 199 // Force allocation of hash table backing store for hidden properties. |
200 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); | 200 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); |
201 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); | 201 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); |
202 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); | 202 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); |
203 | 203 |
204 // Simulate a full heap so that generating an identity hash code | 204 // Simulate a full heap so that generating an identity hash code |
205 // in subsequent calls will request GC. | 205 // in subsequent calls will request GC. |
206 SimulateFullSpace(HEAP->new_space()); | 206 SimulateFullSpace(HEAP->new_space()); |
207 SimulateFullSpace(HEAP->old_pointer_space()); | 207 SimulateFullSpace(HEAP->old_pointer_space()); |
208 | 208 |
209 // Calling Lookup() should not cause GC ever. | 209 // Calling Lookup() should not cause GC ever. |
210 CHECK(table->Lookup(*key)->IsTheHole()); | 210 CHECK(table->Lookup(*key)->IsTheHole()); |
211 | 211 |
212 // Calling Put() should request GC by returning a failure. | 212 // Calling Put() should request GC by returning a failure. |
213 CHECK(table->Put(*key, *key)->IsRetryAfterGC()); | 213 CHECK(table->Put(*key, *key)->IsRetryAfterGC()); |
214 } | 214 } |
215 #endif | 215 #endif |
OLD | NEW |