Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Side by Side Diff: test/cctest/test-heap.cc

Issue 1374163002: [heap] Reland Remove retry space from AllocateRaw. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 delete[] str; 1174 delete[] str;
1175 1175
1176 // Add a Map object to look for. 1176 // Add a Map object to look for.
1177 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); 1177 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map());
1178 1178
1179 CHECK_EQ(objs_count, next_objs_index); 1179 CHECK_EQ(objs_count, next_objs_index);
1180 CHECK_EQ(objs_count, ObjectsFoundInHeap(CcTest::heap(), objs, objs_count)); 1180 CHECK_EQ(objs_count, ObjectsFoundInHeap(CcTest::heap(), objs, objs_count));
1181 } 1181 }
1182 1182
1183 1183
1184 static int LenFromSize(int size) {
1185 return (size - FixedArray::kHeaderSize) / kPointerSize;
1186 }
1187
1188
1189 HEAP_TEST(Regression39128) {
1190 // Test case for crbug.com/39128.
1191 CcTest::InitializeVM();
1192 Isolate* isolate = CcTest::i_isolate();
1193 Heap* heap = CcTest::heap();
1194
1195 // Increase the chance of 'bump-the-pointer' allocation in old space.
1196 heap->CollectAllGarbage();
1197
1198 v8::HandleScope scope(CcTest::isolate());
1199
1200 // The plan: create JSObject which references objects in new space.
1201 // Then clone this object (forcing it to go into old space) and check
1202 // that region dirty marks are updated correctly.
1203
1204 // Step 1: prepare a map for the object. We add 1 inobject property to it.
1205 // Create a map with single inobject property.
1206 Handle<Map> my_map = Map::Create(CcTest::i_isolate(), 1);
1207 int n_properties = my_map->GetInObjectProperties();
1208 CHECK_GT(n_properties, 0);
1209
1210 int object_size = my_map->instance_size();
1211
1212 // Step 2: allocate a lot of objects so to almost fill new space: we need
1213 // just enough room to allocate JSObject and thus fill the newspace.
1214
1215 int allocation_amount = Min(FixedArray::kMaxSize,
1216 Page::kMaxRegularHeapObjectSize + kPointerSize);
1217 int allocation_len = LenFromSize(allocation_amount);
1218 NewSpace* new_space = heap->new_space();
1219 DisableInlineAllocationSteps(new_space);
1220 Address* top_addr = new_space->allocation_top_address();
1221 Address* limit_addr = new_space->allocation_limit_address();
1222 while ((*limit_addr - *top_addr) > allocation_amount) {
1223 CHECK(!heap->always_allocate());
1224 Object* array = heap->AllocateFixedArray(allocation_len).ToObjectChecked();
1225 CHECK(new_space->Contains(array));
1226 }
1227
1228 // Step 3: now allocate fixed array and JSObject to fill the whole new space.
1229 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size);
1230 int fixed_array_len = LenFromSize(to_fill);
1231 CHECK(fixed_array_len < FixedArray::kMaxLength);
1232
1233 CHECK(!heap->always_allocate());
1234 Object* array = heap->AllocateFixedArray(fixed_array_len).ToObjectChecked();
1235 CHECK(new_space->Contains(array));
1236
1237 Object* object = heap->AllocateJSObjectFromMap(*my_map).ToObjectChecked();
1238 CHECK(new_space->Contains(object));
1239 JSObject* jsobject = JSObject::cast(object);
1240 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
1241 CHECK_EQ(0, jsobject->properties()->length());
1242 // Create a reference to object in new space in jsobject.
1243 FieldIndex index = FieldIndex::ForInObjectOffset(
1244 JSObject::kHeaderSize - kPointerSize);
1245 jsobject->FastPropertyAtPut(index, array);
1246
1247 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr));
1248
1249 // Step 4: clone jsobject, but force always allocate first to create a clone
1250 // in old pointer space.
1251 Address old_space_top = heap->old_space()->top();
1252 AlwaysAllocateScope aa_scope(isolate);
1253 Object* clone_obj = heap->CopyJSObject(jsobject).ToObjectChecked();
1254 JSObject* clone = JSObject::cast(clone_obj);
1255 if (clone->address() != old_space_top) {
1256 // Alas, got allocated from free list, we cannot do checks.
1257 return;
1258 }
1259 CHECK(heap->old_space()->Contains(clone->address()));
1260 }
1261
1262
1263 UNINITIALIZED_TEST(TestCodeFlushing) { 1184 UNINITIALIZED_TEST(TestCodeFlushing) {
1264 // If we do not flush code this test is invalid. 1185 // If we do not flush code this test is invalid.
1265 if (!FLAG_flush_code) return; 1186 if (!FLAG_flush_code) return;
1266 i::FLAG_allow_natives_syntax = true; 1187 i::FLAG_allow_natives_syntax = true;
1267 i::FLAG_optimize_for_size = false; 1188 i::FLAG_optimize_for_size = false;
1268 v8::Isolate::CreateParams create_params; 1189 v8::Isolate::CreateParams create_params;
1269 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); 1190 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
1270 v8::Isolate* isolate = v8::Isolate::New(create_params); 1191 v8::Isolate* isolate = v8::Isolate::New(create_params);
1271 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1192 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1272 isolate->Enter(); 1193 isolate->Enter();
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after
3684 3605
3685 isolate->SetUseCounterCallback(MockUseCounterCallback); 3606 isolate->SetUseCounterCallback(MockUseCounterCallback);
3686 3607
3687 forced_gc_counter = 0; 3608 forced_gc_counter = 0;
3688 const char* source = "gc();"; 3609 const char* source = "gc();";
3689 CompileRun(source); 3610 CompileRun(source);
3690 CHECK_GT(forced_gc_counter, 0); 3611 CHECK_GT(forced_gc_counter, 0);
3691 } 3612 }
3692 3613
3693 3614
3694 TEST(Regress2237) {
3695 i::FLAG_stress_compaction = false;
3696 CcTest::InitializeVM();
3697 Isolate* isolate = CcTest::i_isolate();
3698 Factory* factory = isolate->factory();
3699 v8::HandleScope scope(CcTest::isolate());
3700 Handle<String> slice(CcTest::heap()->empty_string());
3701
3702 {
3703 // Generate a parent that lives in new-space.
3704 v8::HandleScope inner_scope(CcTest::isolate());
3705 const char* c = "This text is long enough to trigger sliced strings.";
3706 Handle<String> s = factory->NewStringFromAsciiChecked(c);
3707 CHECK(s->IsSeqOneByteString());
3708 CHECK(CcTest::heap()->InNewSpace(*s));
3709
3710 // Generate a sliced string that is based on the above parent and
3711 // lives in old-space.
3712 SimulateFullSpace(CcTest::heap()->new_space());
3713 AlwaysAllocateScope always_allocate(isolate);
3714 Handle<String> t = factory->NewProperSubString(s, 5, 35);
3715 CHECK(t->IsSlicedString());
3716 CHECK(!CcTest::heap()->InNewSpace(*t));
3717 *slice.location() = *t.location();
3718 }
3719
3720 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
3721 CcTest::heap()->CollectAllGarbage();
3722 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
3723 }
3724
3725
3726 #ifdef OBJECT_PRINT 3615 #ifdef OBJECT_PRINT
3727 TEST(PrintSharedFunctionInfo) { 3616 TEST(PrintSharedFunctionInfo) {
3728 CcTest::InitializeVM(); 3617 CcTest::InitializeVM();
3729 v8::HandleScope scope(CcTest::isolate()); 3618 v8::HandleScope scope(CcTest::isolate());
3730 const char* source = "f = function() { return 987654321; }\n" 3619 const char* source = "f = function() { return 987654321; }\n"
3731 "g = function() { return 123456789; }\n"; 3620 "g = function() { return 123456789; }\n";
3732 CompileRun(source); 3621 CompileRun(source);
3733 Handle<JSFunction> g = 3622 Handle<JSFunction> g =
3734 v8::Utils::OpenHandle( 3623 v8::Utils::OpenHandle(
3735 *v8::Handle<v8::Function>::Cast( 3624 *v8::Handle<v8::Function>::Cast(
(...skipping 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after
6515 // The CollectGarbage call above starts sweeper threads. 6404 // The CollectGarbage call above starts sweeper threads.
6516 // The crash will happen if the following two functions 6405 // The crash will happen if the following two functions
6517 // are called before sweeping finishes. 6406 // are called before sweeping finishes.
6518 heap->StartIncrementalMarking(); 6407 heap->StartIncrementalMarking();
6519 heap->FinalizeIncrementalMarkingIfComplete("test"); 6408 heap->FinalizeIncrementalMarkingIfComplete("test");
6520 } 6409 }
6521 6410
6522 6411
6523 } // namespace internal 6412 } // namespace internal
6524 } // namespace v8 6413 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698