| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Call mark compact GC, and it should pass. | 121 // Call mark compact GC, and it should pass. |
| 122 heap->CollectGarbage(OLD_POINTER_SPACE); | 122 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 TEST(MarkCompactCollector) { | 126 TEST(MarkCompactCollector) { |
| 127 FLAG_incremental_marking = false; | 127 FLAG_incremental_marking = false; |
| 128 CcTest::InitializeVM(); | 128 CcTest::InitializeVM(); |
| 129 Isolate* isolate = CcTest::i_isolate(); | 129 Isolate* isolate = CcTest::i_isolate(); |
| 130 Heap* heap = isolate->heap(); | 130 Heap* heap = isolate->heap(); |
| 131 Factory* factory = isolate->factory(); |
| 131 | 132 |
| 132 v8::HandleScope sc(CcTest::isolate()); | 133 v8::HandleScope sc(CcTest::isolate()); |
| 133 Handle<GlobalObject> global(isolate->context()->global_object()); | 134 Handle<GlobalObject> global(isolate->context()->global_object()); |
| 134 | 135 |
| 135 // call mark-compact when heap is empty | 136 // call mark-compact when heap is empty |
| 136 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); | 137 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); |
| 137 | 138 |
| 138 // keep allocating garbage in new space until it fails | 139 // keep allocating garbage in new space until it fails |
| 139 const int ARRAY_SIZE = 100; | 140 const int ARRAY_SIZE = 100; |
| 140 Object* array; | 141 Object* array; |
| 141 MaybeObject* maybe_array; | 142 MaybeObject* maybe_array; |
| 142 do { | 143 do { |
| 143 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); | 144 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); |
| 144 } while (maybe_array->ToObject(&array)); | 145 } while (maybe_array->ToObject(&array)); |
| 145 heap->CollectGarbage(NEW_SPACE, "trigger 2"); | 146 heap->CollectGarbage(NEW_SPACE, "trigger 2"); |
| 146 | 147 heap->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); |
| 147 array = heap->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); | |
| 148 | 148 |
| 149 // keep allocating maps until it fails | 149 // keep allocating maps until it fails |
| 150 Object* mapp; | 150 Object* map; |
| 151 MaybeObject* maybe_mapp; | 151 MaybeObject* maybe_map; |
| 152 do { | 152 do { |
| 153 maybe_mapp = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 153 maybe_map = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 154 } while (maybe_mapp->ToObject(&mapp)); | 154 } while (maybe_map->ToObject(&map)); |
| 155 heap->CollectGarbage(MAP_SPACE, "trigger 3"); | 155 heap->CollectGarbage(MAP_SPACE, "trigger 3"); |
| 156 mapp = heap->AllocateMap(JS_OBJECT_TYPE, | 156 heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize)->ToObjectChecked(); |
| 157 JSObject::kHeaderSize)->ToObjectChecked(); | |
| 158 | 157 |
| 159 // allocate a garbage | 158 { HandleScope scope(isolate); |
| 160 String* func_name = String::cast( | 159 // allocate a garbage |
| 161 heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); | 160 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); |
| 162 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( | 161 Handle<JSFunction> function = factory->NewFunction( |
| 163 heap->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); | 162 func_name, factory->undefined_value()); |
| 164 JSFunction* function = JSFunction::cast( | 163 Handle<Map> initial_map = factory->NewMap( |
| 165 heap->AllocateFunction(*isolate->sloppy_function_map(), | 164 JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 166 function_share, | 165 function->set_initial_map(*initial_map); |
| 167 heap->undefined_value())->ToObjectChecked()); | 166 JSReceiver::SetProperty(global, func_name, function, NONE, SLOPPY).Check(); |
| 168 Map* initial_map = | |
| 169 Map::cast(heap->AllocateMap(JS_OBJECT_TYPE, | |
| 170 JSObject::kHeaderSize)->ToObjectChecked()); | |
| 171 function->set_initial_map(initial_map); | |
| 172 JSReceiver::SetProperty( | |
| 173 global, handle(func_name), handle(function), NONE, SLOPPY).Check(); | |
| 174 | 167 |
| 175 JSObject* obj = JSObject::cast( | 168 factory->NewJSObject(function); |
| 176 heap->AllocateJSObject(function)->ToObjectChecked()); | 169 } |
| 170 |
| 177 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); | 171 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); |
| 178 | 172 |
| 179 func_name = String::cast( | 173 { HandleScope scope(isolate); |
| 180 heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); | 174 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); |
| 181 CHECK(JSReceiver::HasLocalProperty(global, handle(func_name))); | 175 CHECK(JSReceiver::HasLocalProperty(global, func_name)); |
| 182 Object* func_value = isolate->context()->global_object()-> | 176 Handle<Object> func_value = Object::GetProperty(global, func_name); |
| 183 GetProperty(func_name)->ToObjectChecked(); | 177 CHECK(func_value->IsJSFunction()); |
| 184 CHECK(func_value->IsJSFunction()); | 178 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
| 185 function = JSFunction::cast(func_value); | 179 Handle<JSObject> obj = factory->NewJSObject(function); |
| 186 | 180 |
| 187 obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked()); | 181 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); |
| 188 String* obj_name = | 182 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY).Check(); |
| 189 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); | 183 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
| 190 JSReceiver::SetProperty( | 184 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
| 191 global, handle(obj_name), handle(obj), NONE, SLOPPY).Check(); | 185 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); |
| 192 String* prop_name = | 186 } |
| 193 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); | |
| 194 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | |
| 195 JSReceiver::SetProperty( | |
| 196 handle(obj), handle(prop_name), twenty_three, NONE, SLOPPY).Check(); | |
| 197 | 187 |
| 198 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); | 188 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); |
| 199 | 189 |
| 200 obj_name = | 190 { HandleScope scope(isolate); |
| 201 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); | 191 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); |
| 202 CHECK(JSReceiver::HasLocalProperty(global, handle(obj_name))); | 192 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); |
| 203 CHECK(isolate->context()->global_object()-> | 193 Handle<Object> object = Object::GetProperty(global, obj_name); |
| 204 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); | 194 CHECK(object->IsJSObject()); |
| 205 obj = JSObject::cast(isolate->context()->global_object()-> | 195 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
| 206 GetProperty(obj_name)->ToObjectChecked()); | 196 CHECK_EQ(*Object::GetProperty(object, prop_name), Smi::FromInt(23)); |
| 207 prop_name = | 197 } |
| 208 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); | |
| 209 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); | |
| 210 } | 198 } |
| 211 | 199 |
| 212 | 200 |
| 213 // TODO(1600): compaction of map space is temporary removed from GC. | 201 // TODO(1600): compaction of map space is temporary removed from GC. |
| 214 #if 0 | 202 #if 0 |
| 215 static Handle<Map> CreateMap(Isolate* isolate) { | 203 static Handle<Map> CreateMap(Isolate* isolate) { |
| 216 return isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 204 return isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 217 } | 205 } |
| 218 | 206 |
| 219 | 207 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 524 |
| 537 | 525 |
| 538 TEST(RegressJoinThreadsOnIsolateDeinit) { | 526 TEST(RegressJoinThreadsOnIsolateDeinit) { |
| 539 intptr_t size_limit = ShortLivingIsolate() * 2; | 527 intptr_t size_limit = ShortLivingIsolate() * 2; |
| 540 for (int i = 0; i < 10; i++) { | 528 for (int i = 0; i < 10; i++) { |
| 541 CHECK_GT(size_limit, ShortLivingIsolate()); | 529 CHECK_GT(size_limit, ShortLivingIsolate()); |
| 542 } | 530 } |
| 543 } | 531 } |
| 544 | 532 |
| 545 #endif // __linux__ and !USE_SIMULATOR | 533 #endif // __linux__ and !USE_SIMULATOR |
| OLD | NEW |