| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 #ifdef DEBUG | 167 #ifdef DEBUG |
| 168 template<class HashSet> | 168 template<class HashSet> |
| 169 static void TestHashSetCausesGC(Handle<HashSet> table) { | 169 static void TestHashSetCausesGC(Handle<HashSet> table) { |
| 170 Isolate* isolate = CcTest::i_isolate(); | 170 Isolate* isolate = CcTest::i_isolate(); |
| 171 Factory* factory = isolate->factory(); | 171 Factory* factory = isolate->factory(); |
| 172 | 172 |
| 173 Handle<JSObject> key = factory->NewJSArray(0); | 173 Handle<JSObject> key = factory->NewJSArray(0); |
| 174 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); | |
| 175 | |
| 176 // Force allocation of hash table backing store for hidden properties. | |
| 177 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); | |
| 178 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); | |
| 179 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); | |
| 180 | 174 |
| 181 // Simulate a full heap so that generating an identity hash code | 175 // Simulate a full heap so that generating an identity hash code |
| 182 // in subsequent calls will request GC. | 176 // in subsequent calls will request GC. |
| 183 SimulateFullSpace(CcTest::heap()->new_space()); | 177 SimulateFullSpace(CcTest::heap()->new_space()); |
| 184 SimulateFullSpace(CcTest::heap()->old_space()); | 178 SimulateFullSpace(CcTest::heap()->old_space()); |
| 185 | 179 |
| 186 // Calling Contains() should not cause GC ever. | 180 // Calling Contains() should not cause GC ever. |
| 187 int gc_count = isolate->heap()->gc_count(); | 181 int gc_count = isolate->heap()->gc_count(); |
| 188 CHECK(!table->Contains(key)); | 182 CHECK(!table->Contains(key)); |
| 189 CHECK(gc_count == isolate->heap()->gc_count()); | 183 CHECK(gc_count == isolate->heap()->gc_count()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 201 #endif | 195 #endif |
| 202 | 196 |
| 203 | 197 |
| 204 #ifdef DEBUG | 198 #ifdef DEBUG |
| 205 template<class HashMap> | 199 template<class HashMap> |
| 206 static void TestHashMapCausesGC(Handle<HashMap> table) { | 200 static void TestHashMapCausesGC(Handle<HashMap> table) { |
| 207 Isolate* isolate = CcTest::i_isolate(); | 201 Isolate* isolate = CcTest::i_isolate(); |
| 208 Factory* factory = isolate->factory(); | 202 Factory* factory = isolate->factory(); |
| 209 | 203 |
| 210 Handle<JSObject> key = factory->NewJSArray(0); | 204 Handle<JSObject> key = factory->NewJSArray(0); |
| 211 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); | |
| 212 | |
| 213 // Force allocation of hash table backing store for hidden properties. | |
| 214 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); | |
| 215 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); | |
| 216 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); | |
| 217 | 205 |
| 218 // Simulate a full heap so that generating an identity hash code | 206 // Simulate a full heap so that generating an identity hash code |
| 219 // in subsequent calls will request GC. | 207 // in subsequent calls will request GC. |
| 220 SimulateFullSpace(CcTest::heap()->new_space()); | 208 SimulateFullSpace(CcTest::heap()->new_space()); |
| 221 SimulateFullSpace(CcTest::heap()->old_space()); | 209 SimulateFullSpace(CcTest::heap()->old_space()); |
| 222 | 210 |
| 223 // Calling Lookup() should not cause GC ever. | 211 // Calling Lookup() should not cause GC ever. |
| 224 CHECK(table->Lookup(key)->IsTheHole()); | 212 CHECK(table->Lookup(key)->IsTheHole()); |
| 225 | 213 |
| 226 // Calling Put() should request GC by returning a failure. | 214 // Calling Put() should request GC by returning a failure. |
| 227 int gc_count = isolate->heap()->gc_count(); | 215 int gc_count = isolate->heap()->gc_count(); |
| 228 HashMap::Put(table, key, key); | 216 HashMap::Put(table, key, key); |
| 229 CHECK(gc_count < isolate->heap()->gc_count()); | 217 CHECK(gc_count < isolate->heap()->gc_count()); |
| 230 } | 218 } |
| 231 | 219 |
| 232 | 220 |
| 233 TEST(ObjectHashTableCausesGC) { | 221 TEST(ObjectHashTableCausesGC) { |
| 234 i::FLAG_stress_compaction = false; | 222 i::FLAG_stress_compaction = false; |
| 235 LocalContext context; | 223 LocalContext context; |
| 236 v8::HandleScope scope(context->GetIsolate()); | 224 v8::HandleScope scope(context->GetIsolate()); |
| 237 Isolate* isolate = CcTest::i_isolate(); | 225 Isolate* isolate = CcTest::i_isolate(); |
| 238 TestHashMapCausesGC(ObjectHashTable::New(isolate, 1)); | 226 TestHashMapCausesGC(ObjectHashTable::New(isolate, 1)); |
| 239 } | 227 } |
| 240 #endif | 228 #endif |
| 241 | 229 |
| 242 } // namespace | 230 } // namespace |
| OLD | NEW |