src/os/solaris/vm/osThread_solaris.hpp

Tue, 06 Mar 2012 12:36:59 +0100

author
rbackman
date
Tue, 06 Mar 2012 12:36:59 +0100
changeset 3709
0105f367a14c
parent 3481
de268c8a8075
child 3796
960a442eae91
permissions
-rw-r--r--

7160570: Intrinsification support for tracing framework
Reviewed-by: sla, never

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef OS_SOLARIS_VM_OSTHREAD_SOLARIS_HPP
    26 #define OS_SOLARIS_VM_OSTHREAD_SOLARIS_HPP
    28 // This is embedded via include into the class OSThread
    30  private:
    31   thread_t _thread_id;         // Solaris thread id
    32   uint     _lwp_id;            // lwp ID, only used with bound threads
    33   int      _native_priority;   // Saved native priority when starting
    34                                // a bound thread
    35   sigset_t _caller_sigmask;    // Caller's signal mask
    36   bool     _vm_created_thread; // true if the VM created this thread,
    37                                // false if primary thread or attached thread
    38  public:
    39   static size_t thread_id_size()   { return sizeof(thread_t); }
    40   thread_t thread_id() const       { return _thread_id; }
    41   uint     lwp_id() const          { return _lwp_id; }
    42   int      native_priority() const { return _native_priority; }
    44   // Set and get state of _vm_created_thread flag
    45   void set_vm_created()           { _vm_created_thread = true; }
    46   bool is_vm_created()            { return _vm_created_thread; }
    48   // Methods to save/restore caller's signal mask
    49   sigset_t  caller_sigmask() const       { return _caller_sigmask; }
    50   void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
    52 #ifndef PRODUCT
    53   // Used for debugging, return a unique integer for each thread.
    54   int thread_identifier() const   { return _thread_id; }
    55 #endif
    56 #ifdef ASSERT
    57   // On solaris reposition can fail in two ways:
    58   // 1: a mismatched pc, because signal is delivered too late, target thread
    59   //    is resumed.
    60   // 2: on a timeout where signal is lost, target thread is resumed.
    61   bool valid_reposition_failure() {
    62     // only 1 and 2 can happen and we can handle both of them
    63     return true;
    64   }
    65 #endif
    66   void set_thread_id(thread_t id)    { _thread_id = id; }
    67   void set_lwp_id(uint id)           { _lwp_id = id; }
    68   void set_native_priority(int prio) { _native_priority = prio; }
    70  // ***************************************************************
    71  // interrupt support.  interrupts (using signals) are used to get
    72  // the thread context (get_thread_pc), to set the thread context
    73  // (set_thread_pc), and to implement java.lang.Thread.interrupt.
    74  // ***************************************************************
    76  public:
    78   class InterruptArguments : StackObj {
    79    private:
    80     Thread*     _thread;   // the thread to signal was dispatched to
    81     ucontext_t* _ucontext; // the machine context at the time of the signal
    83    public:
    84     InterruptArguments(Thread* thread, ucontext_t* ucontext) {
    85       _thread   = thread;
    86       _ucontext = ucontext;
    87     }
    89     Thread*     thread()   const { return _thread;   }
    90     ucontext_t* ucontext() const { return _ucontext; }
    91   };
    93   // There are currently no asynchronous callbacks - and we'd better not
    94   // support them in the future either, as they need to be deallocated from
    95   // the interrupt handler, which is not safe; they also require locks to
    96   // protect the callback queue.
    98   class Sync_Interrupt_Callback : private StackObj {
    99    protected:
   100     volatile bool _is_done;
   101     Monitor*      _sync;
   102     Thread*       _target;
   103    public:
   104     Sync_Interrupt_Callback(Monitor * sync) {
   105       _is_done = false;  _target = NULL;  _sync = sync;
   106     }
   108     bool is_done() const               { return _is_done; }
   109     Thread* target() const             { return _target;  }
   111     int interrupt(Thread * target, int timeout);
   113     // override to implement the callback.
   114     virtual void execute(InterruptArguments *args) = 0;
   116     void leave_callback();
   117   };
   119  private:
   121   Sync_Interrupt_Callback * volatile _current_callback;
   122   enum {
   123     callback_in_progress = 1
   124   };
   125   Mutex * _current_callback_lock;       // only used on v8
   127  public:
   129   int set_interrupt_callback    (Sync_Interrupt_Callback * cb);
   130   void remove_interrupt_callback(Sync_Interrupt_Callback * cb);
   131   void do_interrupt_callbacks_at_interrupt(InterruptArguments *args);
   133  // ***************************************************************
   134  // java.lang.Thread.interrupt state.
   135  // ***************************************************************
   137  private:
   139   JavaThreadState      _saved_interrupt_thread_state;       // the thread state before a system call -- restored afterward
   141  public:
   144   JavaThreadState   saved_interrupt_thread_state()                              { return _saved_interrupt_thread_state; }
   145   void              set_saved_interrupt_thread_state(JavaThreadState state)     { _saved_interrupt_thread_state = state; }
   147   static void       handle_spinlock_contention(int tries);                      // Used for thread local eden locking
   149   // ***************************************************************
   150   // Platform dependent initialization and cleanup
   151   // ***************************************************************
   153 private:
   155   void pd_initialize();
   156   void pd_destroy();
   158 #endif // OS_SOLARIS_VM_OSTHREAD_SOLARIS_HPP

mercurial