< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




2796 // Solaris allocates memory by pages.
2797 int os::vm_allocation_granularity() {
2798   assert(os::Linux::page_size() != -1, "must call os::init");
2799   return os::Linux::page_size();
2800 }
2801 
2802 // Rationale behind this function:
2803 //  current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
2804 //  mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
2805 //  samples for JITted code. Here we create private executable mapping over the code cache
2806 //  and then we can use standard (well, almost, as mapping can change) way to provide
2807 //  info for the reporting script by storing timestamp and location of symbol
2808 void linux_wrap_code(char* base, size_t size) {
2809   static volatile jint cnt = 0;
2810 
2811   if (!UseOprofile) {
2812     return;
2813   }
2814 
2815   char buf[PATH_MAX+1];
2816   int num = Atomic::add(1, &cnt);
2817 
2818   snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d",
2819            os::get_temp_directory(), os::current_process_id(), num);
2820   unlink(buf);
2821 
2822   int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
2823 
2824   if (fd != -1) {
2825     off_t rv = ::lseek(fd, size-2, SEEK_SET);
2826     if (rv != (off_t)-1) {
2827       if (::write(fd, "", 1) == 1) {
2828         mmap(base, size,
2829              PROT_READ|PROT_WRITE|PROT_EXEC,
2830              MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
2831       }
2832     }
2833     ::close(fd);
2834     unlink(buf);
2835   }
2836 }




2796 // Solaris allocates memory by pages.
2797 int os::vm_allocation_granularity() {
2798   assert(os::Linux::page_size() != -1, "must call os::init");
2799   return os::Linux::page_size();
2800 }
2801 
2802 // Rationale behind this function:
2803 //  current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
2804 //  mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
2805 //  samples for JITted code. Here we create private executable mapping over the code cache
2806 //  and then we can use standard (well, almost, as mapping can change) way to provide
2807 //  info for the reporting script by storing timestamp and location of symbol
2808 void linux_wrap_code(char* base, size_t size) {
2809   static volatile jint cnt = 0;
2810 
2811   if (!UseOprofile) {
2812     return;
2813   }
2814 
2815   char buf[PATH_MAX+1];
2816   int num = Atomic::add(&cnt, 1);
2817 
2818   snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d",
2819            os::get_temp_directory(), os::current_process_id(), num);
2820   unlink(buf);
2821 
2822   int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
2823 
2824   if (fd != -1) {
2825     off_t rv = ::lseek(fd, size-2, SEEK_SET);
2826     if (rv != (off_t)-1) {
2827       if (::write(fd, "", 1) == 1) {
2828         mmap(base, size,
2829              PROT_READ|PROT_WRITE|PROT_EXEC,
2830              MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
2831       }
2832     }
2833     ::close(fd);
2834     unlink(buf);
2835   }
2836 }


< prev index next >