src/os/solaris/vm/osThread_solaris.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os/solaris/vm/osThread_solaris.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,151 @@
     1.4 +/*
     1.5 + * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// This is embedded via include into the class OSThread
    1.29 +
    1.30 + private:
    1.31 +
    1.32 +  thread_t _thread_id;      // Solaris thread id
    1.33 +  unsigned int  _lwp_id;    // lwp ID, only used with bound threads
    1.34 +  sigset_t _caller_sigmask; // Caller's signal mask
    1.35 +  bool _vm_created_thread;  // true if the VM create this thread
    1.36 +                            // false if primary thread or attached thread
    1.37 + public:
    1.38 +
    1.39 +  thread_t thread_id() const      { return _thread_id; }
    1.40 +
    1.41 +  unsigned int lwp_id() const     { return _lwp_id; }
    1.42 +
    1.43 +  // Set and get state of _vm_created_thread flag
    1.44 +  void set_vm_created()           { _vm_created_thread = true; }
    1.45 +  bool is_vm_created()            { return _vm_created_thread; }
    1.46 +
    1.47 +  // Methods to save/restore caller's signal mask
    1.48 +  sigset_t  caller_sigmask() const       { return _caller_sigmask; }
    1.49 +  void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
    1.50 +
    1.51 +#ifndef PRODUCT
    1.52 +  // Used for debugging, return a unique integer for each thread.
    1.53 +  int thread_identifier() const   { return _thread_id; }
    1.54 +#endif
    1.55 +#ifdef ASSERT
    1.56 +  // On solaris reposition can fail in two ways:
    1.57 +  // 1: a mismatched pc, because signal is delivered too late, target thread
    1.58 +  //    is resumed.
    1.59 +  // 2: on a timeout where signal is lost, target thread is resumed.
    1.60 +  bool valid_reposition_failure() {
    1.61 +    // only 1 and 2 can happen and we can handle both of them
    1.62 +    return true;
    1.63 +  }
    1.64 +#endif
    1.65 +  void set_thread_id(thread_t id) { _thread_id = id;   }
    1.66 +  void set_lwp_id(unsigned int id){ _lwp_id = id;   }
    1.67 +
    1.68 + // ***************************************************************
    1.69 + // interrupt support.  interrupts (using signals) are used to get
    1.70 + // the thread context (get_thread_pc), to set the thread context
    1.71 + // (set_thread_pc), and to implement java.lang.Thread.interrupt.
    1.72 + // ***************************************************************
    1.73 +
    1.74 + public:
    1.75 +
    1.76 +  class InterruptArguments : StackObj {
    1.77 +   private:
    1.78 +    Thread*     _thread;   // the thread to signal was dispatched to
    1.79 +    ucontext_t* _ucontext; // the machine context at the time of the signal
    1.80 +
    1.81 +   public:
    1.82 +    InterruptArguments(Thread* thread, ucontext_t* ucontext) {
    1.83 +      _thread   = thread;
    1.84 +      _ucontext = ucontext;
    1.85 +    }
    1.86 +
    1.87 +    Thread*     thread()   const { return _thread;   }
    1.88 +    ucontext_t* ucontext() const { return _ucontext; }
    1.89 +  };
    1.90 +
    1.91 +  // There are currently no asynchronous callbacks - and we'd better not
    1.92 +  // support them in the future either, as they need to be deallocated from
    1.93 +  // the interrupt handler, which is not safe; they also require locks to
    1.94 +  // protect the callback queue.
    1.95 +
    1.96 +  class Sync_Interrupt_Callback : private StackObj {
    1.97 +   protected:
    1.98 +    volatile bool _is_done;
    1.99 +    Monitor*      _sync;
   1.100 +    Thread*       _target;
   1.101 +   public:
   1.102 +    Sync_Interrupt_Callback(Monitor * sync) {
   1.103 +      _is_done = false;  _target = NULL;  _sync = sync;
   1.104 +    }
   1.105 +
   1.106 +    bool is_done() const               { return _is_done; }
   1.107 +    Thread* target() const             { return _target;  }
   1.108 +
   1.109 +    int interrupt(Thread * target, int timeout);
   1.110 +
   1.111 +    // override to implement the callback.
   1.112 +    virtual void execute(InterruptArguments *args) = 0;
   1.113 +
   1.114 +    void leave_callback();
   1.115 +  };
   1.116 +
   1.117 + private:
   1.118 +
   1.119 +  Sync_Interrupt_Callback * volatile _current_callback;
   1.120 +  enum {
   1.121 +    callback_in_progress = 1
   1.122 +  };
   1.123 +  Mutex * _current_callback_lock;       // only used on v8
   1.124 +
   1.125 + public:
   1.126 +
   1.127 +  int set_interrupt_callback    (Sync_Interrupt_Callback * cb);
   1.128 +  void remove_interrupt_callback(Sync_Interrupt_Callback * cb);
   1.129 +  void OSThread::do_interrupt_callbacks_at_interrupt(InterruptArguments *args);
   1.130 +
   1.131 + // ***************************************************************
   1.132 + // java.lang.Thread.interrupt state.
   1.133 + // ***************************************************************
   1.134 +
   1.135 + private:
   1.136 +
   1.137 +  JavaThreadState      _saved_interrupt_thread_state;       // the thread state before a system call -- restored afterward
   1.138 +
   1.139 + public:
   1.140 +
   1.141 +
   1.142 +  JavaThreadState   saved_interrupt_thread_state()                              { return _saved_interrupt_thread_state; }
   1.143 +  void              set_saved_interrupt_thread_state(JavaThreadState state)     { _saved_interrupt_thread_state = state; }
   1.144 +
   1.145 +  static void       handle_spinlock_contention(int tries);                      // Used for thread local eden locking
   1.146 +
   1.147 +  // ***************************************************************
   1.148 +  // Platform dependent initialization and cleanup
   1.149 +  // ***************************************************************
   1.150 +
   1.151 +private:
   1.152 +
   1.153 +  void pd_initialize();
   1.154 +  void pd_destroy();

mercurial