| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 TEST(ObjectHashTable) { | 42 TEST(ObjectHashTable) { |
| 43 v8::HandleScope scope; | 43 v8::HandleScope scope; |
| 44 LocalContext context; | 44 LocalContext context; |
| 45 Handle<ObjectHashTable> table = FACTORY->NewObjectHashTable(23); | 45 Handle<ObjectHashTable> table = FACTORY->NewObjectHashTable(23); |
| 46 Handle<JSObject> a = FACTORY->NewJSArray(7); | 46 Handle<JSObject> a = FACTORY->NewJSArray(7); |
| 47 Handle<JSObject> b = FACTORY->NewJSArray(11); | 47 Handle<JSObject> b = FACTORY->NewJSArray(11); |
| 48 table = PutIntoObjectHashTable(table, a, b); | 48 table = PutIntoObjectHashTable(table, a, b); |
| 49 CHECK_EQ(table->NumberOfElements(), 1); | 49 CHECK_EQ(table->NumberOfElements(), 1); |
| 50 CHECK_EQ(table->Lookup(*a), *b); | 50 CHECK_EQ(table->Lookup(*a), *b); |
| 51 CHECK_EQ(table->Lookup(*b), HEAP->undefined_value()); | 51 CHECK_EQ(table->Lookup(*b), HEAP->the_hole_value()); |
| 52 | 52 |
| 53 // Keys still have to be valid after objects were moved. | 53 // Keys still have to be valid after objects were moved. |
| 54 HEAP->CollectGarbage(NEW_SPACE); | 54 HEAP->CollectGarbage(NEW_SPACE); |
| 55 CHECK_EQ(table->NumberOfElements(), 1); | 55 CHECK_EQ(table->NumberOfElements(), 1); |
| 56 CHECK_EQ(table->Lookup(*a), *b); | 56 CHECK_EQ(table->Lookup(*a), *b); |
| 57 CHECK_EQ(table->Lookup(*b), HEAP->undefined_value()); | 57 CHECK_EQ(table->Lookup(*b), HEAP->the_hole_value()); |
| 58 | 58 |
| 59 // Keys that are overwritten should not change number of elements. | 59 // Keys that are overwritten should not change number of elements. |
| 60 table = PutIntoObjectHashTable(table, a, FACTORY->NewJSArray(13)); | 60 table = PutIntoObjectHashTable(table, a, FACTORY->NewJSArray(13)); |
| 61 CHECK_EQ(table->NumberOfElements(), 1); | 61 CHECK_EQ(table->NumberOfElements(), 1); |
| 62 CHECK_NE(table->Lookup(*a), *b); | 62 CHECK_NE(table->Lookup(*a), *b); |
| 63 | 63 |
| 64 // Keys mapped to undefined should be removed permanently. | 64 // Keys mapped to the hole should be removed permanently. |
| 65 table = PutIntoObjectHashTable(table, a, FACTORY->undefined_value()); | 65 table = PutIntoObjectHashTable(table, a, FACTORY->the_hole_value()); |
| 66 CHECK_EQ(table->NumberOfElements(), 0); | 66 CHECK_EQ(table->NumberOfElements(), 0); |
| 67 CHECK_EQ(table->NumberOfDeletedElements(), 1); | 67 CHECK_EQ(table->NumberOfDeletedElements(), 1); |
| 68 CHECK_EQ(table->Lookup(*a), HEAP->undefined_value()); | 68 CHECK_EQ(table->Lookup(*a), HEAP->the_hole_value()); |
| 69 | 69 |
| 70 // Keys should map back to their respective values and also should get | 70 // Keys should map back to their respective values and also should get |
| 71 // an identity hash code generated. | 71 // an identity hash code generated. |
| 72 for (int i = 0; i < 100; i++) { | 72 for (int i = 0; i < 100; i++) { |
| 73 Handle<JSObject> key = FACTORY->NewJSArray(7); | 73 Handle<JSObject> key = FACTORY->NewJSArray(7); |
| 74 Handle<JSObject> value = FACTORY->NewJSArray(11); | 74 Handle<JSObject> value = FACTORY->NewJSArray(11); |
| 75 table = PutIntoObjectHashTable(table, key, value); | 75 table = PutIntoObjectHashTable(table, key, value); |
| 76 CHECK_EQ(table->NumberOfElements(), i + 1); | 76 CHECK_EQ(table->NumberOfElements(), i + 1); |
| 77 CHECK_NE(table->FindEntry(*key), ObjectHashTable::kNotFound); | 77 CHECK_NE(table->FindEntry(*key), ObjectHashTable::kNotFound); |
| 78 CHECK_EQ(table->Lookup(*key), *value); | 78 CHECK_EQ(table->Lookup(*key), *value); |
| 79 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi()); | 79 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Keys never added to the map which already have an identity hash | 82 // Keys never added to the map which already have an identity hash |
| 83 // code should not be found. | 83 // code should not be found. |
| 84 for (int i = 0; i < 100; i++) { | 84 for (int i = 0; i < 100; i++) { |
| 85 Handle<JSObject> key = FACTORY->NewJSArray(7); | 85 Handle<JSObject> key = FACTORY->NewJSArray(7); |
| 86 CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi()); | 86 CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi()); |
| 87 CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound); | 87 CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound); |
| 88 CHECK_EQ(table->Lookup(*key), HEAP->undefined_value()); | 88 CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); |
| 89 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi()); | 89 CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Keys that don't have an identity hash should not be found and also | 92 // Keys that don't have an identity hash should not be found and also |
| 93 // should not get an identity hash code generated. | 93 // should not get an identity hash code generated. |
| 94 for (int i = 0; i < 100; i++) { | 94 for (int i = 0; i < 100; i++) { |
| 95 Handle<JSObject> key = FACTORY->NewJSArray(7); | 95 Handle<JSObject> key = FACTORY->NewJSArray(7); |
| 96 CHECK_EQ(table->Lookup(*key), HEAP->undefined_value()); | 96 CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); |
| 97 CHECK_EQ(key->GetIdentityHash(OMIT_CREATION), HEAP->undefined_value()); | 97 CHECK_EQ(key->GetIdentityHash(OMIT_CREATION), HEAP->undefined_value()); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 #ifdef DEBUG | 102 #ifdef DEBUG |
| 103 TEST(ObjectHashSetCausesGC) { | 103 TEST(ObjectHashSetCausesGC) { |
| 104 v8::HandleScope scope; | 104 v8::HandleScope scope; |
| 105 LocalContext context; | 105 LocalContext context; |
| 106 Handle<ObjectHashSet> table = FACTORY->NewObjectHashSet(1); | 106 Handle<ObjectHashSet> table = FACTORY->NewObjectHashSet(1); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 133 // in subsequent calls will request GC. | 133 // in subsequent calls will request GC. |
| 134 FLAG_gc_interval = 0; | 134 FLAG_gc_interval = 0; |
| 135 | 135 |
| 136 // Calling Lookup() should not cause GC ever. | 136 // Calling Lookup() should not cause GC ever. |
| 137 CHECK(table->Lookup(*key)->IsUndefined()); | 137 CHECK(table->Lookup(*key)->IsUndefined()); |
| 138 | 138 |
| 139 // Calling Put() should request GC by returning a failure. | 139 // Calling Put() should request GC by returning a failure. |
| 140 CHECK(table->Put(*key, *key)->IsRetryAfterGC()); | 140 CHECK(table->Put(*key, *key)->IsRetryAfterGC()); |
| 141 } | 141 } |
| 142 #endif | 142 #endif |
| OLD | NEW |