| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/full-codegen.h" | 7 #include "src/full-codegen.h" |
| 8 #include "src/macro-assembler.h" | 8 #include "src/macro-assembler.h" |
| 9 #include "src/mark-compact.h" | 9 #include "src/mark-compact.h" |
| 10 #include "src/msan.h" | 10 #include "src/msan.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 ASSERT(size_ >= size); | 315 ASSERT(size_ >= size); |
| 316 size_ -= size; | 316 size_ -= size; |
| 317 | 317 |
| 318 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size)); | 318 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size)); |
| 319 | 319 |
| 320 if (executable == EXECUTABLE) { | 320 if (executable == EXECUTABLE) { |
| 321 ASSERT(size_executable_ >= size); | 321 ASSERT(size_executable_ >= size); |
| 322 size_executable_ -= size; | 322 size_executable_ -= size; |
| 323 } | 323 } |
| 324 // Code which is part of the code-range does not have its own VirtualMemory. | 324 // Code which is part of the code-range does not have its own VirtualMemory. |
| 325 ASSERT(!isolate_->code_range()->contains( | 325 ASSERT(isolate_->code_range() == NULL || |
| 326 static_cast<Address>(reservation->address()))); | 326 !isolate_->code_range()->contains( |
| 327 ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists()); | 327 static_cast<Address>(reservation->address()))); |
| 328 ASSERT(executable == NOT_EXECUTABLE || |
| 329 isolate_->code_range() == NULL || |
| 330 !isolate_->code_range()->valid()); |
| 328 reservation->Release(); | 331 reservation->Release(); |
| 329 } | 332 } |
| 330 | 333 |
| 331 | 334 |
| 332 void MemoryAllocator::FreeMemory(Address base, | 335 void MemoryAllocator::FreeMemory(Address base, |
| 333 size_t size, | 336 size_t size, |
| 334 Executability executable) { | 337 Executability executable) { |
| 335 // TODO(gc) make code_range part of memory allocator? | 338 // TODO(gc) make code_range part of memory allocator? |
| 336 ASSERT(size_ >= size); | 339 ASSERT(size_ >= size); |
| 337 size_ -= size; | 340 size_ -= size; |
| 338 | 341 |
| 339 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size)); | 342 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size)); |
| 340 | 343 |
| 341 if (executable == EXECUTABLE) { | 344 if (executable == EXECUTABLE) { |
| 342 ASSERT(size_executable_ >= size); | 345 ASSERT(size_executable_ >= size); |
| 343 size_executable_ -= size; | 346 size_executable_ -= size; |
| 344 } | 347 } |
| 345 if (isolate_->code_range()->contains(static_cast<Address>(base))) { | 348 if (isolate_->code_range() != NULL && |
| 349 isolate_->code_range()->contains(static_cast<Address>(base))) { |
| 346 ASSERT(executable == EXECUTABLE); | 350 ASSERT(executable == EXECUTABLE); |
| 347 isolate_->code_range()->FreeRawMemory(base, size); | 351 isolate_->code_range()->FreeRawMemory(base, size); |
| 348 } else { | 352 } else { |
| 349 ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists()); | 353 ASSERT(executable == NOT_EXECUTABLE || |
| 354 isolate_->code_range() == NULL || |
| 355 !isolate_->code_range()->valid()); |
| 350 bool result = VirtualMemory::ReleaseRegion(base, size); | 356 bool result = VirtualMemory::ReleaseRegion(base, size); |
| 351 USE(result); | 357 USE(result); |
| 352 ASSERT(result); | 358 ASSERT(result); |
| 353 } | 359 } |
| 354 } | 360 } |
| 355 | 361 |
| 356 | 362 |
| 357 Address MemoryAllocator::ReserveAlignedMemory(size_t size, | 363 Address MemoryAllocator::ReserveAlignedMemory(size_t size, |
| 358 size_t alignment, | 364 size_t alignment, |
| 359 VirtualMemory* controller) { | 365 VirtualMemory* controller) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 size_t length = commit_size - committed_size; | 521 size_t length = commit_size - committed_size; |
| 516 if (reservation_.IsReserved()) { | 522 if (reservation_.IsReserved()) { |
| 517 Executability executable = IsFlagSet(IS_EXECUTABLE) | 523 Executability executable = IsFlagSet(IS_EXECUTABLE) |
| 518 ? EXECUTABLE : NOT_EXECUTABLE; | 524 ? EXECUTABLE : NOT_EXECUTABLE; |
| 519 if (!heap()->isolate()->memory_allocator()->CommitMemory( | 525 if (!heap()->isolate()->memory_allocator()->CommitMemory( |
| 520 start, length, executable)) { | 526 start, length, executable)) { |
| 521 return false; | 527 return false; |
| 522 } | 528 } |
| 523 } else { | 529 } else { |
| 524 CodeRange* code_range = heap_->isolate()->code_range(); | 530 CodeRange* code_range = heap_->isolate()->code_range(); |
| 525 ASSERT(code_range->exists() && IsFlagSet(IS_EXECUTABLE)); | 531 ASSERT(code_range != NULL && code_range->valid() && |
| 532 IsFlagSet(IS_EXECUTABLE)); |
| 526 if (!code_range->CommitRawMemory(start, length)) return false; | 533 if (!code_range->CommitRawMemory(start, length)) return false; |
| 527 } | 534 } |
| 528 | 535 |
| 529 if (Heap::ShouldZapGarbage()) { | 536 if (Heap::ShouldZapGarbage()) { |
| 530 heap_->isolate()->memory_allocator()->ZapBlock(start, length); | 537 heap_->isolate()->memory_allocator()->ZapBlock(start, length); |
| 531 } | 538 } |
| 532 } else if (commit_size < committed_size) { | 539 } else if (commit_size < committed_size) { |
| 533 ASSERT(commit_size > 0); | 540 ASSERT(commit_size > 0); |
| 534 // Shrink the committed area. | 541 // Shrink the committed area. |
| 535 size_t length = committed_size - commit_size; | 542 size_t length = committed_size - commit_size; |
| 536 Address start = address() + committed_size + guard_size - length; | 543 Address start = address() + committed_size + guard_size - length; |
| 537 if (reservation_.IsReserved()) { | 544 if (reservation_.IsReserved()) { |
| 538 if (!reservation_.Uncommit(start, length)) return false; | 545 if (!reservation_.Uncommit(start, length)) return false; |
| 539 } else { | 546 } else { |
| 540 CodeRange* code_range = heap_->isolate()->code_range(); | 547 CodeRange* code_range = heap_->isolate()->code_range(); |
| 541 ASSERT(code_range->exists() && IsFlagSet(IS_EXECUTABLE)); | 548 ASSERT(code_range != NULL && code_range->valid() && |
| 549 IsFlagSet(IS_EXECUTABLE)); |
| 542 if (!code_range->UncommitRawMemory(start, length)) return false; | 550 if (!code_range->UncommitRawMemory(start, length)) return false; |
| 543 } | 551 } |
| 544 } | 552 } |
| 545 | 553 |
| 546 area_end_ = area_start_ + requested; | 554 area_end_ = area_start_ + requested; |
| 547 return true; | 555 return true; |
| 548 } | 556 } |
| 549 | 557 |
| 550 | 558 |
| 551 void MemoryChunk::InsertAfter(MemoryChunk* other) { | 559 void MemoryChunk::InsertAfter(MemoryChunk* other) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 StringEvent("MemoryAllocator::AllocateRawMemory", | 629 StringEvent("MemoryAllocator::AllocateRawMemory", |
| 622 "V8 Executable Allocation capacity exceeded")); | 630 "V8 Executable Allocation capacity exceeded")); |
| 623 return NULL; | 631 return NULL; |
| 624 } | 632 } |
| 625 | 633 |
| 626 // Size of header (not executable) plus area (executable). | 634 // Size of header (not executable) plus area (executable). |
| 627 size_t commit_size = RoundUp(CodePageGuardStartOffset() + commit_area_size, | 635 size_t commit_size = RoundUp(CodePageGuardStartOffset() + commit_area_size, |
| 628 OS::CommitPageSize()); | 636 OS::CommitPageSize()); |
| 629 // Allocate executable memory either from code range or from the | 637 // Allocate executable memory either from code range or from the |
| 630 // OS. | 638 // OS. |
| 631 if (isolate_->code_range()->exists()) { | 639 if (isolate_->code_range() != NULL && isolate_->code_range()->valid()) { |
| 632 base = isolate_->code_range()->AllocateRawMemory(chunk_size, | 640 base = isolate_->code_range()->AllocateRawMemory(chunk_size, |
| 633 commit_size, | 641 commit_size, |
| 634 &chunk_size); | 642 &chunk_size); |
| 635 ASSERT(IsAligned(reinterpret_cast<intptr_t>(base), | 643 ASSERT(IsAligned(reinterpret_cast<intptr_t>(base), |
| 636 MemoryChunk::kAlignment)); | 644 MemoryChunk::kAlignment)); |
| 637 if (base == NULL) return NULL; | 645 if (base == NULL) return NULL; |
| 638 size_ += chunk_size; | 646 size_ += chunk_size; |
| 639 // Update executable memory size. | 647 // Update executable memory size. |
| 640 size_executable_ += chunk_size; | 648 size_executable_ += chunk_size; |
| 641 } else { | 649 } else { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 break; | 1051 break; |
| 1044 case MAP_SPACE: | 1052 case MAP_SPACE: |
| 1045 size = 16 * kPointerSize * KB; | 1053 size = 16 * kPointerSize * KB; |
| 1046 break; | 1054 break; |
| 1047 case CELL_SPACE: | 1055 case CELL_SPACE: |
| 1048 size = 16 * kPointerSize * KB; | 1056 size = 16 * kPointerSize * KB; |
| 1049 break; | 1057 break; |
| 1050 case PROPERTY_CELL_SPACE: | 1058 case PROPERTY_CELL_SPACE: |
| 1051 size = 8 * kPointerSize * KB; | 1059 size = 8 * kPointerSize * KB; |
| 1052 break; | 1060 break; |
| 1053 case CODE_SPACE: | 1061 case CODE_SPACE: { |
| 1054 if (heap()->isolate()->code_range()->exists()) { | 1062 CodeRange* code_range = heap()->isolate()->code_range(); |
| 1063 if (code_range != NULL && code_range->valid()) { |
| 1055 // When code range exists, code pages are allocated in a special way | 1064 // When code range exists, code pages are allocated in a special way |
| 1056 // (from the reserved code range). That part of the code is not yet | 1065 // (from the reserved code range). That part of the code is not yet |
| 1057 // upgraded to handle small pages. | 1066 // upgraded to handle small pages. |
| 1058 size = AreaSize(); | 1067 size = AreaSize(); |
| 1059 } else { | 1068 } else { |
| 1060 size = RoundUp( | 1069 size = RoundUp( |
| 1061 480 * KB * FullCodeGenerator::kBootCodeSizeMultiplier / 100, | 1070 480 * KB * FullCodeGenerator::kBootCodeSizeMultiplier / 100, |
| 1062 kPointerSize); | 1071 kPointerSize); |
| 1063 } | 1072 } |
| 1064 break; | 1073 break; |
| 1074 } |
| 1065 default: | 1075 default: |
| 1066 UNREACHABLE(); | 1076 UNREACHABLE(); |
| 1067 } | 1077 } |
| 1068 return Min(size, AreaSize()); | 1078 return Min(size, AreaSize()); |
| 1069 } | 1079 } |
| 1070 | 1080 |
| 1071 | 1081 |
| 1072 int PagedSpace::CountTotalPages() { | 1082 int PagedSpace::CountTotalPages() { |
| 1073 PageIterator it(this); | 1083 PageIterator it(this); |
| 1074 int count = 0; | 1084 int count = 0; |
| (...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3113 object->ShortPrint(); | 3123 object->ShortPrint(); |
| 3114 PrintF("\n"); | 3124 PrintF("\n"); |
| 3115 } | 3125 } |
| 3116 printf(" --------------------------------------\n"); | 3126 printf(" --------------------------------------\n"); |
| 3117 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3127 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3118 } | 3128 } |
| 3119 | 3129 |
| 3120 #endif // DEBUG | 3130 #endif // DEBUG |
| 3121 | 3131 |
| 3122 } } // namespace v8::internal | 3132 } } // namespace v8::internal |
| OLD | NEW |