hotspot/src/os/solaris/vm/osThread_solaris.hpp
author xdono
Thu, 02 Oct 2008 19:58:19 -0700
changeset 1217 5eb97f366a6a
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// This is embedded via include into the class OSThread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  thread_t _thread_id;      // Solaris thread id
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  unsigned int  _lwp_id;    // lwp ID, only used with bound threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  sigset_t _caller_sigmask; // Caller's signal mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  bool _vm_created_thread;  // true if the VM create this thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
                            // false if primary thread or attached thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  thread_t thread_id() const      { return _thread_id; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  unsigned int lwp_id() const     { return _lwp_id; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Set and get state of _vm_created_thread flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  void set_vm_created()           { _vm_created_thread = true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  bool is_vm_created()            { return _vm_created_thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Methods to save/restore caller's signal mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  sigset_t  caller_sigmask() const       { return _caller_sigmask; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Used for debugging, return a unique integer for each thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  int thread_identifier() const   { return _thread_id; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // On solaris reposition can fail in two ways:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // 1: a mismatched pc, because signal is delivered too late, target thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  //    is resumed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // 2: on a timeout where signal is lost, target thread is resumed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  bool valid_reposition_failure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // only 1 and 2 can happen and we can handle both of them
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  void set_thread_id(thread_t id) { _thread_id = id;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void set_lwp_id(unsigned int id){ _lwp_id = id;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
 // ***************************************************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
 // interrupt support.  interrupts (using signals) are used to get
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
 // the thread context (get_thread_pc), to set the thread context
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
 // (set_thread_pc), and to implement java.lang.Thread.interrupt.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 // ***************************************************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  class InterruptArguments : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
   private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    Thread*     _thread;   // the thread to signal was dispatched to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    ucontext_t* _ucontext; // the machine context at the time of the signal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
   public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    InterruptArguments(Thread* thread, ucontext_t* ucontext) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      _thread   = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      _ucontext = ucontext;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    Thread*     thread()   const { return _thread;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    ucontext_t* ucontext() const { return _ucontext; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // There are currently no asynchronous callbacks - and we'd better not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // support them in the future either, as they need to be deallocated from
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // the interrupt handler, which is not safe; they also require locks to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // protect the callback queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  class Sync_Interrupt_Callback : private StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
   protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    volatile bool _is_done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    Monitor*      _sync;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    Thread*       _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
   public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    Sync_Interrupt_Callback(Monitor * sync) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      _is_done = false;  _target = NULL;  _sync = sync;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    bool is_done() const               { return _is_done; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    Thread* target() const             { return _target;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    int interrupt(Thread * target, int timeout);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    // override to implement the callback.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    virtual void execute(InterruptArguments *args) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    void leave_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  Sync_Interrupt_Callback * volatile _current_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    callback_in_progress = 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  Mutex * _current_callback_lock;       // only used on v8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  int set_interrupt_callback    (Sync_Interrupt_Callback * cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void remove_interrupt_callback(Sync_Interrupt_Callback * cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void OSThread::do_interrupt_callbacks_at_interrupt(InterruptArguments *args);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
 // ***************************************************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 // java.lang.Thread.interrupt state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
 // ***************************************************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  JavaThreadState      _saved_interrupt_thread_state;       // the thread state before a system call -- restored afterward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  JavaThreadState   saved_interrupt_thread_state()                              { return _saved_interrupt_thread_state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void              set_saved_interrupt_thread_state(JavaThreadState state)     { _saved_interrupt_thread_state = state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static void       handle_spinlock_contention(int tries);                      // Used for thread local eden locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // ***************************************************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Platform dependent initialization and cleanup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // ***************************************************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void pd_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  void pd_destroy();