< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




2735 
2736   // Initialize signal semaphore
2737   sig_sem = new Semaphore();
2738 }
2739 
2740 void os::signal_notify(int sig) {
2741   if (sig_sem != NULL) {
2742     Atomic::inc(&pending_signals[sig]);
2743     sig_sem->signal();
2744   } else {
2745     // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2746     // initialization isn't called.
2747     assert(ReduceSignalUsage, "signal semaphore should be created");
2748   }
2749 }
2750 
2751 static int check_pending_signals() {
2752   for (;;) {
2753     for (int i = 0; i < NSIG + 1; i++) {
2754       jint n = pending_signals[i];
2755       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2756         return i;
2757       }
2758     }
2759     JavaThread *thread = JavaThread::current();
2760     ThreadBlockInVM tbivm(thread);
2761 
2762     bool threadIsSuspended;
2763     do {
2764       thread->set_suspend_equivalent();
2765       // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
2766       sig_sem->wait();
2767 
2768       // were we externally suspended while we were waiting?
2769       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2770       if (threadIsSuspended) {
2771         // The semaphore has been incremented, but while we were waiting
2772         // another thread suspended us. We don't want to continue running
2773         // while suspended because that would surprise the thread that
2774         // suspended us.
2775         sig_sem->signal();


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 }




2735 
2736   // Initialize signal semaphore
2737   sig_sem = new Semaphore();
2738 }
2739 
2740 void os::signal_notify(int sig) {
2741   if (sig_sem != NULL) {
2742     Atomic::inc(&pending_signals[sig]);
2743     sig_sem->signal();
2744   } else {
2745     // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2746     // initialization isn't called.
2747     assert(ReduceSignalUsage, "signal semaphore should be created");
2748   }
2749 }
2750 
2751 static int check_pending_signals() {
2752   for (;;) {
2753     for (int i = 0; i < NSIG + 1; i++) {
2754       jint n = pending_signals[i];
2755       if (n > 0 && n == Atomic::cmpxchg(&pending_signals[i], n, n - 1)) {
2756         return i;
2757       }
2758     }
2759     JavaThread *thread = JavaThread::current();
2760     ThreadBlockInVM tbivm(thread);
2761 
2762     bool threadIsSuspended;
2763     do {
2764       thread->set_suspend_equivalent();
2765       // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
2766       sig_sem->wait();
2767 
2768       // were we externally suspended while we were waiting?
2769       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2770       if (threadIsSuspended) {
2771         // The semaphore has been incremented, but while we were waiting
2772         // another thread suspended us. We don't want to continue running
2773         // while suspended because that would surprise the thread that
2774         // suspended us.
2775         sig_sem->signal();


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 >