< prev index next >

src/hotspot/os/bsd/os_bsd.cpp

Print this page




1877 // Solaris allocates memory by pages.
1878 int os::vm_allocation_granularity() {
1879   assert(os::Bsd::page_size() != -1, "must call os::init");
1880   return os::Bsd::page_size();
1881 }
1882 
1883 // Rationale behind this function:
1884 //  current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
1885 //  mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
1886 //  samples for JITted code. Here we create private executable mapping over the code cache
1887 //  and then we can use standard (well, almost, as mapping can change) way to provide
1888 //  info for the reporting script by storing timestamp and location of symbol
1889 void bsd_wrap_code(char* base, size_t size) {
1890   static volatile jint cnt = 0;
1891 
1892   if (!UseOprofile) {
1893     return;
1894   }
1895 
1896   char buf[PATH_MAX + 1];
1897   int num = Atomic::add(1, &cnt);
1898 
1899   snprintf(buf, PATH_MAX + 1, "%s/hs-vm-%d-%d",
1900            os::get_temp_directory(), os::current_process_id(), num);
1901   unlink(buf);
1902 
1903   int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
1904 
1905   if (fd != -1) {
1906     off_t rv = ::lseek(fd, size-2, SEEK_SET);
1907     if (rv != (off_t)-1) {
1908       if (::write(fd, "", 1) == 1) {
1909         mmap(base, size,
1910              PROT_READ|PROT_WRITE|PROT_EXEC,
1911              MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
1912       }
1913     }
1914     ::close(fd);
1915     unlink(buf);
1916   }
1917 }


3247 }
3248 
3249 uint os::processor_id() {
3250   volatile int* mapping = get_apic_to_processor_mapping();
3251 
3252   uint eax = 0xb;
3253   uint ebx;
3254   uint ecx = 0;
3255   uint edx;
3256 
3257   __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3258 
3259   // Map from APIC id to a unique logical processor ID in the expected
3260   // [0, num_processors) range.
3261 
3262   uint apic_id = edx;
3263   int processor_id = Atomic::load(&mapping[apic_id]);
3264 
3265   while (processor_id < 0) {
3266     if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
3267       Atomic::store(&mapping[apic_id], Atomic::add(1, &next_processor_id) - 1);
3268     }
3269     processor_id = Atomic::load(&mapping[apic_id]);
3270   }
3271 
3272   return (uint)processor_id;
3273 }
3274 #endif
3275 
3276 void os::set_native_thread_name(const char *name) {
3277 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
3278   // This is only supported in Snow Leopard and beyond
3279   if (name != NULL) {
3280     // Add a "Java: " prefix to the name
3281     char buf[MAXTHREADNAMESIZE];
3282     snprintf(buf, sizeof(buf), "Java: %s", name);
3283     pthread_setname_np(buf);
3284   }
3285 #endif
3286 }
3287 




1877 // Solaris allocates memory by pages.
1878 int os::vm_allocation_granularity() {
1879   assert(os::Bsd::page_size() != -1, "must call os::init");
1880   return os::Bsd::page_size();
1881 }
1882 
1883 // Rationale behind this function:
1884 //  current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
1885 //  mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
1886 //  samples for JITted code. Here we create private executable mapping over the code cache
1887 //  and then we can use standard (well, almost, as mapping can change) way to provide
1888 //  info for the reporting script by storing timestamp and location of symbol
1889 void bsd_wrap_code(char* base, size_t size) {
1890   static volatile jint cnt = 0;
1891 
1892   if (!UseOprofile) {
1893     return;
1894   }
1895 
1896   char buf[PATH_MAX + 1];
1897   int num = Atomic::add(&cnt, 1);
1898 
1899   snprintf(buf, PATH_MAX + 1, "%s/hs-vm-%d-%d",
1900            os::get_temp_directory(), os::current_process_id(), num);
1901   unlink(buf);
1902 
1903   int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
1904 
1905   if (fd != -1) {
1906     off_t rv = ::lseek(fd, size-2, SEEK_SET);
1907     if (rv != (off_t)-1) {
1908       if (::write(fd, "", 1) == 1) {
1909         mmap(base, size,
1910              PROT_READ|PROT_WRITE|PROT_EXEC,
1911              MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
1912       }
1913     }
1914     ::close(fd);
1915     unlink(buf);
1916   }
1917 }


3247 }
3248 
3249 uint os::processor_id() {
3250   volatile int* mapping = get_apic_to_processor_mapping();
3251 
3252   uint eax = 0xb;
3253   uint ebx;
3254   uint ecx = 0;
3255   uint edx;
3256 
3257   __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3258 
3259   // Map from APIC id to a unique logical processor ID in the expected
3260   // [0, num_processors) range.
3261 
3262   uint apic_id = edx;
3263   int processor_id = Atomic::load(&mapping[apic_id]);
3264 
3265   while (processor_id < 0) {
3266     if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
3267       Atomic::store(&mapping[apic_id], Atomic::add(&next_processor_id, 1) - 1);
3268     }
3269     processor_id = Atomic::load(&mapping[apic_id]);
3270   }
3271 
3272   return (uint)processor_id;
3273 }
3274 #endif
3275 
3276 void os::set_native_thread_name(const char *name) {
3277 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
3278   // This is only supported in Snow Leopard and beyond
3279   if (name != NULL) {
3280     // Add a "Java: " prefix to the name
3281     char buf[MAXTHREADNAMESIZE];
3282     snprintf(buf, sizeof(buf), "Java: %s", name);
3283     pthread_setname_np(buf);
3284   }
3285 #endif
3286 }
3287 


< prev index next >