Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 t->depth = GetStackTrace(t->stack, kMaxStackDepth-1, 3); | 460 t->depth = GetStackTrace(t->stack, kMaxStackDepth-1, 3); |
| 461 t->size = growth; | 461 t->size = growth; |
| 462 t->stack[kMaxStackDepth-1] = reinterpret_cast<void*>(Static::growth_stacks()); | 462 t->stack[kMaxStackDepth-1] = reinterpret_cast<void*>(Static::growth_stacks()); |
| 463 Static::set_growth_stacks(t); | 463 Static::set_growth_stacks(t); |
| 464 } | 464 } |
| 465 | 465 |
| 466 bool PageHeap::GrowHeap(Length n) { | 466 bool PageHeap::GrowHeap(Length n) { |
| 467 ASSERT(kMaxPages >= kMinSystemAlloc); | 467 ASSERT(kMaxPages >= kMinSystemAlloc); |
| 468 if (n > kMaxValidPages) return false; | 468 if (n > kMaxValidPages) return false; |
| 469 Length ask = (n>kMinSystemAlloc) ? n : static_cast<Length>(kMinSystemAlloc); | 469 Length ask = (n>kMinSystemAlloc) ? n : static_cast<Length>(kMinSystemAlloc); |
| 470 // For most allocators it's ok to check for size here as they won't generally | |
| 471 // grow existing mappings. Some implementations, such as the Linux brk heap | |
| 472 // implementation will however require additional checks. | |
| 473 if (!IsContiguousAllocSizePermitted(n << kPageShift)) | |
|
jln (very slow on Chromium)
2013/01/11 06:02:29
It's a bit ugly to have the check here *and* in th
| |
| 474 return false; | |
| 470 size_t actual_size; | 475 size_t actual_size; |
| 471 void* ptr = TCMalloc_SystemAlloc(ask << kPageShift, &actual_size, kPageSize); | 476 void* ptr = TCMalloc_SystemAlloc(ask << kPageShift, &actual_size, kPageSize); |
| 472 if (ptr == NULL) { | 477 if (ptr == NULL) { |
| 473 if (n < ask) { | 478 if (n < ask) { |
| 474 // Try growing just "n" pages | 479 // Try growing just "n" pages |
| 475 ask = n; | 480 ask = n; |
| 476 ptr = TCMalloc_SystemAlloc(ask << kPageShift, &actual_size, kPageSize); | 481 ptr = TCMalloc_SystemAlloc(ask << kPageShift, &actual_size, kPageSize); |
| 477 } | 482 } |
| 478 if (ptr == NULL) return false; | 483 if (ptr == NULL) return false; |
| 479 } | 484 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 CHECK_CONDITION(s->location == freelist); // NORMAL or RETURNED | 542 CHECK_CONDITION(s->location == freelist); // NORMAL or RETURNED |
| 538 CHECK_CONDITION(s->length >= min_pages); | 543 CHECK_CONDITION(s->length >= min_pages); |
| 539 CHECK_CONDITION(s->length <= max_pages); | 544 CHECK_CONDITION(s->length <= max_pages); |
| 540 CHECK_CONDITION(GetDescriptor(s->start) == s); | 545 CHECK_CONDITION(GetDescriptor(s->start) == s); |
| 541 CHECK_CONDITION(GetDescriptor(s->start+s->length-1) == s); | 546 CHECK_CONDITION(GetDescriptor(s->start+s->length-1) == s); |
| 542 } | 547 } |
| 543 return true; | 548 return true; |
| 544 } | 549 } |
| 545 | 550 |
| 546 } // namespace tcmalloc | 551 } // namespace tcmalloc |
| OLD | NEW |