OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 19 matching lines...) Expand all Loading... |
30 #include "sys/stat.h" | 30 #include "sys/stat.h" |
31 #include "v8.h" | 31 #include "v8.h" |
32 | 32 |
33 #include "debug.h" | 33 #include "debug.h" |
34 #include "ic-inl.h" | 34 #include "ic-inl.h" |
35 #include "runtime.h" | 35 #include "runtime.h" |
36 #include "serialize.h" | 36 #include "serialize.h" |
37 #include "scopeinfo.h" | 37 #include "scopeinfo.h" |
38 #include "snapshot.h" | 38 #include "snapshot.h" |
39 #include "cctest.h" | 39 #include "cctest.h" |
| 40 #include "spaces.h" |
| 41 #include "objects.h" |
40 | 42 |
41 using namespace v8::internal; | 43 using namespace v8::internal; |
42 | 44 |
43 static const unsigned kCounters = 256; | 45 static const unsigned kCounters = 256; |
44 static int local_counters[kCounters]; | 46 static int local_counters[kCounters]; |
45 static const char* local_counter_names[kCounters]; | 47 static const char* local_counter_names[kCounters]; |
46 | 48 |
47 | 49 |
48 static unsigned CounterHash(const char* s) { | 50 static unsigned CounterHash(const char* s) { |
49 unsigned hash = 0; | 51 unsigned hash = 0; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 v8::Persistent<v8::Context> env = v8::Context::New(); | 272 v8::Persistent<v8::Context> env = v8::Context::New(); |
271 env->Enter(); | 273 env->Enter(); |
272 | 274 |
273 const char* c_source = "\"1234\".length"; | 275 const char* c_source = "\"1234\".length"; |
274 v8::Local<v8::String> source = v8::String::New(c_source); | 276 v8::Local<v8::String> source = v8::String::New(c_source); |
275 v8::Local<v8::Script> script = v8::Script::Compile(source); | 277 v8::Local<v8::Script> script = v8::Script::Compile(source); |
276 CHECK_EQ(4, script->Run()->Int32Value()); | 278 CHECK_EQ(4, script->Run()->Int32Value()); |
277 } | 279 } |
278 | 280 |
279 | 281 |
| 282 TEST(LinearAllocation) { |
| 283 v8::V8::Initialize(); |
| 284 NewSpace* new_space = Heap::new_space(); |
| 285 PagedSpace* old_pointer_space = Heap::old_pointer_space(); |
| 286 PagedSpace* old_data_space = Heap::old_data_space(); |
| 287 PagedSpace* code_space = Heap::code_space(); |
| 288 PagedSpace* map_space = Heap::map_space(); |
| 289 PagedSpace* cell_space = Heap::cell_space(); |
| 290 int new_space_max = 512 * KB; |
| 291 for (int size = 1000; size < 5 * MB; size *= 1.5) { |
| 292 bool gc_performed = true; |
| 293 while (gc_performed) { |
| 294 gc_performed = false; |
| 295 if (size < new_space_max) { |
| 296 if (!new_space->ReserveSpace(size)) { |
| 297 Heap::CollectGarbage(size, NEW_SPACE); |
| 298 gc_performed = true; |
| 299 CHECK(new_space->ReserveSpace(size)); |
| 300 } |
| 301 } |
| 302 if (!old_pointer_space->ReserveSpace(size)) { |
| 303 Heap::CollectGarbage(size, OLD_POINTER_SPACE); |
| 304 gc_performed = true; |
| 305 CHECK(old_pointer_space->ReserveSpace(size)); |
| 306 } |
| 307 if (!(old_data_space->ReserveSpace(size))) { |
| 308 Heap::CollectGarbage(size, OLD_DATA_SPACE); |
| 309 gc_performed = true; |
| 310 CHECK(old_data_space->ReserveSpace(size)); |
| 311 } |
| 312 if (!(code_space->ReserveSpace(size))) { |
| 313 Heap::CollectGarbage(size, CODE_SPACE); |
| 314 gc_performed = true; |
| 315 CHECK(code_space->ReserveSpace(size)); |
| 316 } |
| 317 if (!(map_space->ReserveSpace(size))) { |
| 318 Heap::CollectGarbage(size, MAP_SPACE); |
| 319 gc_performed = true; |
| 320 CHECK(map_space->ReserveSpace(size)); |
| 321 } |
| 322 if (!(cell_space->ReserveSpace(size))) { |
| 323 Heap::CollectGarbage(size, CELL_SPACE); |
| 324 gc_performed = true; |
| 325 CHECK(cell_space->ReserveSpace(size));; |
| 326 } |
| 327 } |
| 328 LinearAllocationScope scope; |
| 329 const int kSmallFixedArrayLength = 4; |
| 330 const int kSmallFixedArraySize = |
| 331 FixedArray::kHeaderSize + kSmallFixedArrayLength * kPointerSize; |
| 332 const int kSmallStringLength = 16; |
| 333 const int kSmallStringSize = |
| 334 SeqAsciiString::kHeaderSize + kSmallStringLength; |
| 335 const int kMapSize = Map::kSize; |
| 336 |
| 337 if (size < new_space_max) { |
| 338 Object* new_last = NULL; |
| 339 for (int i = 0; |
| 340 i + kSmallFixedArraySize <= size; i += kSmallFixedArraySize) { |
| 341 Object* o = Heap::AllocateFixedArray(kSmallFixedArrayLength); |
| 342 if (new_last != NULL) { |
| 343 CHECK_EQ(reinterpret_cast<char*>(o), |
| 344 reinterpret_cast<char*>(new_last) + kSmallFixedArraySize); |
| 345 } |
| 346 new_last = o; |
| 347 } |
| 348 } |
| 349 |
| 350 Object* new_pointer = NULL; |
| 351 for (int i = 0; |
| 352 i + kSmallFixedArraySize <= size; |
| 353 i += kSmallFixedArraySize) { |
| 354 Object* o = Heap::AllocateFixedArray(kSmallFixedArrayLength, TENURED); |
| 355 int old_page_fullness = i % Page::kPageSize; |
| 356 int page_fullness = (i + kSmallFixedArraySize) % Page::kPageSize; |
| 357 if (page_fullness < old_page_fullness || |
| 358 page_fullness > Page::kObjectAreaSize) { |
| 359 i = RoundUp(i, Page::kPageSize); |
| 360 new_pointer = NULL; |
| 361 } |
| 362 if (new_pointer != NULL) { |
| 363 CHECK_EQ(reinterpret_cast<char*>(o), |
| 364 reinterpret_cast<char*>(new_pointer) + kSmallFixedArraySize); |
| 365 } |
| 366 new_pointer = o; |
| 367 } |
| 368 |
| 369 new_pointer = NULL; |
| 370 for (int i = 0; i + kSmallStringSize <= size; i += kSmallStringSize) { |
| 371 Object* o = Heap::AllocateRawAsciiString(kSmallStringLength, TENURED); |
| 372 int old_page_fullness = i % Page::kPageSize; |
| 373 int page_fullness = (i + kSmallStringSize) % Page::kPageSize; |
| 374 if (page_fullness < old_page_fullness || |
| 375 page_fullness > Page::kObjectAreaSize) { |
| 376 i = RoundUp(i, Page::kPageSize); |
| 377 new_pointer = NULL; |
| 378 } |
| 379 if (new_pointer != NULL) { |
| 380 CHECK_EQ(reinterpret_cast<char*>(o), |
| 381 reinterpret_cast<char*>(new_pointer) + kSmallStringSize); |
| 382 } |
| 383 new_pointer = o; |
| 384 } |
| 385 |
| 386 new_pointer = NULL; |
| 387 for (int i = 0; i + kMapSize <= size; i += kMapSize) { |
| 388 Object* o = Heap::AllocateMap(JS_OBJECT_TYPE, 42 * kPointerSize); |
| 389 int old_page_fullness = i % Page::kPageSize; |
| 390 int page_fullness = (i + kMapSize) % Page::kPageSize; |
| 391 if (page_fullness < old_page_fullness || |
| 392 page_fullness > Page::kObjectAreaSize) { |
| 393 i = RoundUp(i, Page::kPageSize); |
| 394 new_pointer = NULL; |
| 395 } |
| 396 if (new_pointer != NULL) { |
| 397 CHECK_EQ(reinterpret_cast<char*>(o), |
| 398 reinterpret_cast<char*>(new_pointer) + kMapSize); |
| 399 } |
| 400 new_pointer = o; |
| 401 } |
| 402 |
| 403 if (size > Page::kObjectAreaSize) { |
| 404 // Support for reserving space in large object space is not there yet, |
| 405 // but using an always-allocate scope is fine for now. |
| 406 AlwaysAllocateScope always; |
| 407 int large_object_array_length = |
| 408 (size - FixedArray::kHeaderSize) / kPointerSize; |
| 409 new_pointer = Heap::AllocateFixedArray(large_object_array_length, |
| 410 TENURED); |
| 411 ASSERT(!new_pointer->IsFailure()); |
| 412 } |
| 413 } |
| 414 } |
| 415 |
| 416 |
280 TEST(TestThatAlwaysSucceeds) { | 417 TEST(TestThatAlwaysSucceeds) { |
281 } | 418 } |
282 | 419 |
283 | 420 |
284 TEST(TestThatAlwaysFails) { | 421 TEST(TestThatAlwaysFails) { |
285 bool ArtificialFailure = false; | 422 bool ArtificialFailure = false; |
286 CHECK(ArtificialFailure); | 423 CHECK(ArtificialFailure); |
287 } | 424 } |
288 | 425 |
289 | 426 |
290 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 427 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
291 bool ArtificialFailure2 = false; | 428 bool ArtificialFailure2 = false; |
292 CHECK(ArtificialFailure2); | 429 CHECK(ArtificialFailure2); |
293 } | 430 } |
OLD | NEW |