OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 fclose(file); | 470 fclose(file); |
471 return NULL; | 471 return NULL; |
472 } | 472 } |
473 void* memory = | 473 void* memory = |
474 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | 474 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
475 return new PosixMemoryMappedFile(file, memory, size); | 475 return new PosixMemoryMappedFile(file, memory, size); |
476 } | 476 } |
477 | 477 |
478 | 478 |
479 PosixMemoryMappedFile::~PosixMemoryMappedFile() { | 479 PosixMemoryMappedFile::~PosixMemoryMappedFile() { |
480 if (memory_) munmap(memory_, size_); | 480 if (memory_) OS::Free(memory_, size_); |
481 fclose(file_); | 481 fclose(file_); |
482 } | 482 } |
483 | 483 |
484 | 484 |
485 void OS::LogSharedLibraryAddresses() { | 485 void OS::LogSharedLibraryAddresses() { |
486 // This function assumes that the layout of the file is as follows: | 486 // This function assumes that the layout of the file is as follows: |
487 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] | 487 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] |
488 // If we encounter an unexpected situation we abort scanning further entries. | 488 // If we encounter an unexpected situation we abort scanning further entries. |
489 FILE* fp = fopen("/proc/self/maps", "r"); | 489 FILE* fp = fopen("/proc/self/maps", "r"); |
490 if (fp == NULL) return; | 490 if (fp == NULL) return; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 // PROT_EXEC so that analysis tools can properly attribute ticks. We | 552 // PROT_EXEC so that analysis tools can properly attribute ticks. We |
553 // do a mmap with a name known by ll_prof.py and immediately munmap | 553 // do a mmap with a name known by ll_prof.py and immediately munmap |
554 // it. This injects a GC marker into the stream of events generated | 554 // it. This injects a GC marker into the stream of events generated |
555 // by the kernel and allows us to synchronize V8 code log and the | 555 // by the kernel and allows us to synchronize V8 code log and the |
556 // kernel log. | 556 // kernel log. |
557 int size = sysconf(_SC_PAGESIZE); | 557 int size = sysconf(_SC_PAGESIZE); |
558 FILE* f = fopen(kGCFakeMmap, "w+"); | 558 FILE* f = fopen(kGCFakeMmap, "w+"); |
559 void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, | 559 void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, |
560 fileno(f), 0); | 560 fileno(f), 0); |
561 ASSERT(addr != MAP_FAILED); | 561 ASSERT(addr != MAP_FAILED); |
562 munmap(addr, size); | 562 OS::Free(addr, size); |
563 fclose(f); | 563 fclose(f); |
564 } | 564 } |
565 | 565 |
566 | 566 |
567 int OS::StackWalk(Vector<OS::StackFrame> frames) { | 567 int OS::StackWalk(Vector<OS::StackFrame> frames) { |
568 // backtrace is a glibc extension. | 568 // backtrace is a glibc extension. |
569 #ifdef __GLIBC__ | 569 #ifdef __GLIBC__ |
570 int frames_size = frames.length(); | 570 int frames_size = frames.length(); |
571 ScopedVector<void*> addresses(frames_size); | 571 ScopedVector<void*> addresses(frames_size); |
572 | 572 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 614 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
615 size_t request_size = RoundUp(size + alignment, | 615 size_t request_size = RoundUp(size + alignment, |
616 static_cast<intptr_t>(OS::AllocateAlignment())); | 616 static_cast<intptr_t>(OS::AllocateAlignment())); |
617 void* reservation = mmap(GetRandomMmapAddr(), | 617 void* reservation = mmap(GetRandomMmapAddr(), |
618 request_size, | 618 request_size, |
619 PROT_NONE, | 619 PROT_NONE, |
620 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, | 620 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, |
621 kMmapFd, | 621 kMmapFd, |
622 kMmapFdOffset); | 622 kMmapFdOffset); |
623 if (reservation == MAP_FAILED) return; | 623 if (reservation == MAP_FAILED) return; |
| 624 |
624 Address base = static_cast<Address>(reservation); | 625 Address base = static_cast<Address>(reservation); |
625 Address aligned_base = RoundUp(base, alignment); | 626 Address aligned_base = RoundUp(base, alignment); |
626 ASSERT(base <= aligned_base); | 627 ASSERT_LE(base, aligned_base); |
627 | 628 |
628 // Unmap extra memory reserved before and after the desired block. | 629 // Unmap extra memory reserved before and after the desired block. |
629 size_t bytes_prior = static_cast<size_t>(aligned_base - base); | 630 if (aligned_base != base) { |
630 if (bytes_prior > 0) { | 631 size_t prefix_size = static_cast<size_t>(aligned_base - base); |
631 munmap(base, bytes_prior); | 632 OS::Free(base, prefix_size); |
632 } | 633 request_size -= prefix_size; |
633 if (static_cast<size_t>(aligned_base - base) < request_size - size) { | |
634 munmap(aligned_base + size, request_size - size - bytes_prior); | |
635 } | 634 } |
636 | 635 |
| 636 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); |
| 637 ASSERT_LE(aligned_size, request_size); |
| 638 |
| 639 if (aligned_size != request_size) { |
| 640 size_t suffix_size = request_size - aligned_size; |
| 641 OS::Free(aligned_base + aligned_size, suffix_size); |
| 642 request_size -= suffix_size; |
| 643 } |
| 644 |
| 645 ASSERT(aligned_size == request_size); |
| 646 |
637 address_ = static_cast<void*>(aligned_base); | 647 address_ = static_cast<void*>(aligned_base); |
638 size_ = size; | 648 size_ = aligned_size; |
639 } | 649 } |
640 | 650 |
641 | 651 |
642 VirtualMemory::~VirtualMemory() { | 652 VirtualMemory::~VirtualMemory() { |
643 if (IsReserved()) { | 653 if (IsReserved()) { |
644 bool result = ReleaseRegion(address(), size()); | 654 bool result = ReleaseRegion(address(), size()); |
645 ASSERT(result); | 655 ASSERT(result); |
646 USE(result); | 656 USE(result); |
647 } | 657 } |
648 } | 658 } |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 | 1222 |
1213 | 1223 |
1214 void Sampler::Stop() { | 1224 void Sampler::Stop() { |
1215 ASSERT(IsActive()); | 1225 ASSERT(IsActive()); |
1216 SignalSender::RemoveActiveSampler(this); | 1226 SignalSender::RemoveActiveSampler(this); |
1217 SetActive(false); | 1227 SetActive(false); |
1218 } | 1228 } |
1219 | 1229 |
1220 | 1230 |
1221 } } // namespace v8::internal | 1231 } } // namespace v8::internal |
OLD | NEW |