changeset 1019:9c1f9ecd294a

class Haiku based on class Solaris, but PlatformEvent and PlatformParker are based on linux version
author bachmann
date Fri, 23 Oct 2009 13:04:31 -0700
parents 7930b62dafc9
children 49478fa0af86
files src/os/haiku/vm/os_haiku.hpp
diffstat 1 files changed, 195 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/haiku/vm/os_haiku.hpp	Fri Oct 23 13:04:31 2009 -0700
@@ -0,0 +1,195 @@
+
+// Haiku_OS defines the interface to Haiku operating systems
+//
+// This class parallels the solaris implementation, without the
+// extra hair for managing the variety of libraries solaris does.
+
+class Haiku {
+  friend class os;
+
+ private:	
+  static void init_thread_fpu_state(void);
+
+  static void try_enable_extended_io();
+
+  // For signal-chaining
+  static unsigned long sigs;                 // mask of signals that have
+                                             // preinstalled signal handlers
+  static struct sigaction *(*get_signal_action)(int);
+  static struct sigaction *get_preinstalled_handler(int);
+  static int (*get_libjsig_version)();
+  static void save_preinstalled_handler(int, struct sigaction&);
+  static void check_signal_handler(int sig);
+  // For overridable signals
+  static int _SIGinterrupt;                  // user-overridable INTERRUPT_SIGNAL
+  static int _SIGasync;                      // user-overridable ASYNC_SIGNAL
+  static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; }
+  static void set_SIGasync(int newsig) { _SIGasync = newsig; }
+
+ public:
+  static int SIGinterrupt() { return _SIGinterrupt; }
+  static int SIGasync() { return _SIGasync; }
+  static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo
+
+  static bool valid_stack_address(Thread* thread, address sp);
+  static bool valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect);
+  static ucontext_t* get_valid_uc_in_signal_handler(Thread* thread,
+    ucontext_t* uc);
+
+  static ExtendedPC  ucontext_get_ExtendedPC(ucontext_t* uc);
+  static intptr_t*   ucontext_get_sp(ucontext_t* uc);
+
+  // For Analyzer Forte AsyncGetCallTrace profiling support:
+  static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc,
+    intptr_t** ret_sp, intptr_t** ret_fp);
+
+  static void hotspot_sigmask(Thread* thread);
+
+ protected:
+  // Haiku-specific interface goes here
+  static julong available_memory();
+  static julong physical_memory() { return _physical_memory; }
+  static julong _physical_memory;
+  static void initialize_system_info();
+  static int _dev_zero_fd;
+  static int get_dev_zero_fd() { return _dev_zero_fd; }
+  static void set_dev_zero_fd(int fd) { _dev_zero_fd = fd; }
+  static char* mmap_chunk(char *addr, size_t size, int flags, int prot);
+  static char* anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed);
+
+  // Workaround for 4352906. thr_stksegment sometimes returns
+  // a bad value for the primordial thread's stack base when
+  // it is called more than one time.
+  // Workaround is to cache the initial value to avoid further
+  // calls to thr_stksegment.
+  // It appears that someone (Hotspot?) is trashing the user's
+  // proc_t structure (note that this is a system struct).
+  static address _main_stack_base;
+
+ public:
+  static void libthread_init();
+  static void synchronization_init();
+  static bool liblgrp_init();
+  // Load miscellaneous symbols.
+  static void misc_sym_init();
+  // This boolean allows users to forward their own non-matching signals
+  // to JVM_handle_solaris_signal, harmlessly.
+  static bool signal_handlers_are_installed;
+
+  static void signal_sets_init();
+  static void install_signal_handlers();
+  static void set_signal_handler(int sig, bool set_installed, bool oktochain);
+  static void init_signal_mem();
+  static bool is_sig_ignored(int sig);
+  static void set_our_sigflags(int, int);
+  static int get_our_sigflags(int);
+
+  // For signal-chaining
+  static bool libjsig_is_loaded; // libjsig that interposes sigaction(),
+                                 // signal(), sigset() is loaded
+  static struct sigaction *get_chained_signal_action(int sig);
+  static bool chained_handler(int sig, siginfo_t *siginfo, void *context);
+
+  enum {
+    clear_interrupted = true
+  };
+  static void setup_interruptible(JavaThread* thread);
+  static void setup_interruptible_already_blocked(JavaThread* thread);
+  static JavaThread* setup_interruptible();
+  static void cleanup_interruptible(JavaThread* thread);
+
+  // perf counter incrementers used by _INTERRUPTIBLE
+
+  static void bump_interrupted_before_count();
+  static void bump_interrupted_during_count();
+
+#ifdef ASSERT
+  static JavaThread* setup_interruptible_native();
+  static void cleanup_interruptible_native(JavaThread* thread);
+#endif
+
+  static sigset_t* unblocked_signals();
+  static sigset_t* vm_signals();
+  static sigset_t* allowdebug_blocked_signals();
+
+  // %%% Following should be promoted to os.hpp:
+  // Trace number of created threads
+  static          jint  _os_thread_limit;
+  static volatile jint  _os_thread_count;
+
+  // Minimum stack size a thread can be created with (allowing
+  // the VM to completely create the thread and enter user code)
+
+  static size_t min_stack_allowed;
+
+  // Stack overflow handling
+
+  static int max_register_window_saves_before_flushing();
+
+  // Stack repair handling
+
+  // none present
+
+};
+
+//
+// From here on, following linux
+//
+
+class PlatformEvent : public CHeapObj {
+  private:
+    double CachePad [4] ;   // increase odds that _mutex is sole occupant of cache line
+    volatile int _Event ;
+    volatile int _nParked ;
+    pthread_mutex_t _mutex  [1] ;
+    pthread_cond_t  _cond   [1] ;
+    double PostPad  [2] ;
+    Thread * _Assoc ;
+
+  public:       // TODO-FIXME: make dtor private
+    ~PlatformEvent() { guarantee (0, "invariant") ; }
+
+  public:
+    PlatformEvent() {
+      int status;
+      status = pthread_cond_init (_cond, NULL);
+      assert_status(status == 0, status, "cond_init");
+      status = pthread_mutex_init (_mutex, NULL);
+      assert_status(status == 0, status, "mutex_init");
+      _Event   = 0 ;
+      _nParked = 0 ;
+      _Assoc   = NULL ;
+    }
+
+    // Use caution with reset() and fired() -- they may require MEMBARs
+    void reset() { _Event = 0 ; }
+    int  fired() { return _Event; }
+    void park () ;
+    void unpark () ;
+    int  TryPark () ;
+    int  park (jlong millis) ;
+    void SetAssociation (Thread * a) { _Assoc = a ; }
+} ;
+
+class PlatformParker : public CHeapObj {
+  protected:
+    pthread_mutex_t _mutex [1] ;
+    pthread_cond_t  _cond  [1] ;
+
+  public:       // TODO-FIXME: make dtor private
+    ~PlatformParker() { guarantee (0, "invariant") ; }
+
+  public:
+    PlatformParker() {
+      int status;
+      status = pthread_cond_init (_cond, NULL);
+      assert_status(status == 0, status, "cond_init");
+      status = pthread_mutex_init (_mutex, NULL);
+      assert_status(status == 0, status, "mutex_init");
+    }
+} ;
+
+
+
+
+