src/share/vm/runtime/os.hpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


 764   // debugging support (mostly used by debug.cpp but also fatal error handler)
 765   static bool find(address pc, outputStream* st = tty); // OS specific function to make sense out of an address
 766 
 767   static bool dont_yield();                     // when true, JVM_Yield() is nop
 768   static void print_statistics();
 769 
 770   // Thread priority helpers (implemented in OS-specific part)
 771   static OSReturn set_native_priority(Thread* thread, int native_prio);
 772   static OSReturn get_native_priority(const Thread* const thread, int* priority_ptr);
 773   static int java_to_os_priority[CriticalPriority + 1];
 774   // Hint to the underlying OS that a task switch would not be good.
 775   // Void return because it's a hint and can fail.
 776   static void hint_no_preempt();
 777 
 778   // Used at creation if requested by the diagnostic flag PauseAtStartup.
 779   // Causes the VM to wait until an external stimulus has been applied
 780   // (for Unix, that stimulus is a signal, for Windows, an external
 781   // ResumeThread call)
 782   static void pause();
 783 


































































































 784  protected:
 785   static long _rand_seed;                   // seed for random number generator
 786   static int _processor_count;              // number of processors
 787 
 788   static char* format_boot_path(const char* format_string,
 789                                 const char* home,
 790                                 int home_len,
 791                                 char fileSep,
 792                                 char pathSep);
 793   static bool set_boot_path(char fileSep, char pathSep);
 794   static char** split_path(const char* path, int* n);
 795 };
 796 
 797 // Note that "PAUSE" is almost always used with synchronization
 798 // so arguably we should provide Atomic::SpinPause() instead
 799 // of the global SpinPause() with C linkage.
 800 // It'd also be eligible for inlining on many platforms.
 801 
 802 extern "C" int SpinPause () ;
 803 extern "C" int SafeFetch32 (int * adr, int errValue) ;


 764   // debugging support (mostly used by debug.cpp but also fatal error handler)
 765   static bool find(address pc, outputStream* st = tty); // OS specific function to make sense out of an address
 766 
 767   static bool dont_yield();                     // when true, JVM_Yield() is nop
 768   static void print_statistics();
 769 
 770   // Thread priority helpers (implemented in OS-specific part)
 771   static OSReturn set_native_priority(Thread* thread, int native_prio);
 772   static OSReturn get_native_priority(const Thread* const thread, int* priority_ptr);
 773   static int java_to_os_priority[CriticalPriority + 1];
 774   // Hint to the underlying OS that a task switch would not be good.
 775   // Void return because it's a hint and can fail.
 776   static void hint_no_preempt();
 777 
 778   // Used at creation if requested by the diagnostic flag PauseAtStartup.
 779   // Causes the VM to wait until an external stimulus has been applied
 780   // (for Unix, that stimulus is a signal, for Windows, an external
 781   // ResumeThread call)
 782   static void pause();
 783 
 784   class SuspendedThreadTaskContext {
 785   public:
 786     SuspendedThreadTaskContext(Thread* thread, void *ucontext) : _thread(thread), _ucontext(ucontext) {}
 787     Thread* thread() const { return _thread; }
 788     void* ucontext() const { return _ucontext; }
 789   private:
 790     Thread* _thread;
 791     void* _ucontext;
 792   };
 793 
 794   class SuspendedThreadTask {
 795   public:
 796     SuspendedThreadTask(Thread* thread) : _thread(thread), _done(false) {}
 797     virtual ~SuspendedThreadTask() {}
 798     void run();
 799     bool is_done() { return _done; }
 800     virtual void do_task(const SuspendedThreadTaskContext& context) = 0;
 801   protected:
 802   private:
 803     void internal_do_task();
 804     Thread* _thread;
 805     bool _done;
 806   };
 807 
 808 #ifndef TARGET_OS_FAMILY_windows
 809   // Suspend/resume support
 810   // Protocol:
 811   //
 812   // a thread starts in SR_RUNNING
 813   //
 814   // SR_RUNNING can go to
 815   //   * SR_SUSPEND_REQUEST when the WatcherThread wants to suspend it
 816   // SR_SUSPEND_REQUEST can go to
 817   //   * SR_RUNNING if WatcherThread decides it waited for SR_SUSPENDED too long (timeout)
 818   //   * SR_SUSPENDED if the stopped thread receives the signal and switches state
 819   // SR_SUSPENDED can go to
 820   //   * SR_WAKEUP_REQUEST when the WatcherThread has done the work and wants to resume
 821   // SR_WAKEUP_REQUEST can go to
 822   //   * SR_RUNNING when the stopped thread receives the signal
 823   //   * SR_WAKEUP_REQUEST on timeout (resend the signal and try again)
 824   class SuspendResume {
 825    public:
 826     enum State {
 827       SR_RUNNING,
 828       SR_SUSPEND_REQUEST,
 829       SR_SUSPENDED,
 830       SR_WAKEUP_REQUEST
 831     };
 832 
 833   private:
 834     volatile State _state;
 835 
 836   private:
 837     /* try to switch state from state "from" to state "to"
 838      * returns the state set after the method is complete
 839      */
 840     State switch_state(State from, State to);
 841 
 842   public:
 843     SuspendResume() : _state(SR_RUNNING) { }
 844 
 845     State state() const { return _state; }
 846 
 847     State request_suspend() {
 848       return switch_state(SR_RUNNING, SR_SUSPEND_REQUEST);
 849     }
 850 
 851     State cancel_suspend() {
 852       return switch_state(SR_SUSPEND_REQUEST, SR_RUNNING);
 853     }
 854 
 855     State suspended() {
 856       return switch_state(SR_SUSPEND_REQUEST, SR_SUSPENDED);
 857     }
 858 
 859     State request_wakeup() {
 860       return switch_state(SR_SUSPENDED, SR_WAKEUP_REQUEST);
 861     }
 862 
 863     State running() {
 864       return switch_state(SR_WAKEUP_REQUEST, SR_RUNNING);
 865     }
 866 
 867     bool is_running() const {
 868       return _state == SR_RUNNING;
 869     }
 870 
 871     bool is_suspend_request() const {
 872       return _state == SR_SUSPEND_REQUEST;
 873     }
 874 
 875     bool is_suspended() const {
 876       return _state == SR_SUSPENDED;
 877     }
 878   };
 879 #endif
 880 
 881 
 882  protected:
 883   static long _rand_seed;                   // seed for random number generator
 884   static int _processor_count;              // number of processors
 885 
 886   static char* format_boot_path(const char* format_string,
 887                                 const char* home,
 888                                 int home_len,
 889                                 char fileSep,
 890                                 char pathSep);
 891   static bool set_boot_path(char fileSep, char pathSep);
 892   static char** split_path(const char* path, int* n);
 893 };
 894 
 895 // Note that "PAUSE" is almost always used with synchronization
 896 // so arguably we should provide Atomic::SpinPause() instead
 897 // of the global SpinPause() with C linkage.
 898 // It'd also be eligible for inlining on many platforms.
 899 
 900 extern "C" int SpinPause () ;
 901 extern "C" int SafeFetch32 (int * adr, int errValue) ;