Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

threadutil.c File Reference


Detailed Description

Utilities for operating the JVM thread state model on this real machine implementation.

Todo:
Timers for Thread.sleep() and Thread.wait() and Object.wait() that use millisecond timers are supported. The variation that supports higher resolution of milliseconds and nanoseconds are not supported, but the millisecond version is used instead.

For internal use only.

This file also serves the dual purpose as a catch-all for development experiments. Due to the fact that the implementation of the Java thread and the supporting rthread structure is deeply embedded in the core of the development of this software, this file has contents that come and go during development. Some functions get staged here before deciding where they really go; some are interim functions for debugging, some were glue that eventually went away. Be careful to remove prototypes to such functions from the appropriate header file.

Control

$URL: https://svn.apache.org/path/name/threadutil.c $ $Id: threadutil.c 0 09/28/2005 dlydick $

Copyright 2005 The Apache Software Foundation or its licensors, as applicable.

Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Version:
$LastChangedRevision: 0 $
Date:
$LastChangedDate: 09/28/2005 $
Author:
$LastChangedBy: dlydick $ Original code contributed by Daniel Lydick on 09/28/2005.

Reference

Definition in file threadutil.c.

#include "arch.h"
#include "jvmcfg.h"
#include "cfmacros.h"
#include "classfile.h"
#include "jvm.h"
#include "jvmclass.h"
#include "util.h"

Go to the source code of this file.

Functions

static void threadutil_c_dummy (void)
rboolean threadutil_holds_lock (jvm_thread_index thridx, jvm_object_hash objhashlock)
 Examine an object to see if a thread owns its monitor lock.
rvoid threadutil_update_blockingevents (jvm_thread_index thridxcurr)
 Complete the UNtimed Thread.join() request and allow threads that have joined this one to resume execution.
rvoid threadutil_update_lock (jvm_thread_index thridxcurr)
rvoid threadutil_update_sleeptime_interval (rvoid)
 Update the interval timer for this thread from java.lang.Thread.sleep() or from a timed java.lang.Thread.wait() or java.lang.Thread.join().
rvoid threadutil_update_wait (jvm_thread_index thridxcurr)

Variables

static char * threadutil_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/threadutil.c $ $Id: threadutil.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable."


Function Documentation

static void threadutil_c_dummy void   )  [static]
 

Definition at line 56 of file threadutil.c.

rvoid threadutil_update_sleeptime_interval rvoid   ) 
 

Update the interval timer for this thread from java.lang.Thread.sleep() or from a timed java.lang.Thread.wait() or java.lang.Thread.join().

This function is designed to be invoked from the timeslice interrupt handler and only from thence. It DOES NOT handle (millisec, nanosec) resolution, only millisecond resolution.

Parameters: rvoid

Returns:
rvoid
< This slot contains a thread

< thread is sleeping

< thread has joined another, but is waiting for a finite time

< thread is waiting, but finite time

Definition at line 84 of file threadutil.c.

References jvm_thread_index_null, JVMCFG_MAX_THREADS, pjvm, rjvm::sleeplock, THREAD, THREAD_STATUS_INUSE, THREAD_STATUS_JOINTIMED, THREAD_STATUS_SLEEP, and THREAD_STATUS_WAITTIMED.

Referenced by timeslice_tick().

rvoid threadutil_update_blockingevents jvm_thread_index  thridxcurr  ) 
 

Complete the UNtimed Thread.join() request and allow threads that have joined this one to resume execution.

This function is typically called when a thread enters the COMPLETE state after finishing its JVM execution.

Review state of thread table, looking for the following conditions. For those that meet them, move thread out of given state and forward to next state. Three functions are used, depending on the current state, threadutil_update_blockingevent() and threadutil_update_wait() and threadutil_update_lock():

   Condition:         Current state: Next state:  threadutil_update_YYY:
   ----------         -------------- -----------  ----------------------
  
   Thread.join()      COMPLETE       N/C              _blockingevents()
   (forever, where
   current thread
   is COMPLETE, and
   target thread is
   BLOCKED, and is
   moved to UNBLOCKED)
  
   Thread.join(n)     COMPLETE       N/C              _blockingevents()
   (timed, where
   n has expired
   on current
   thread or it is
   COMPLETE, and
   target thread
   is BLOCKED, and
   is moved to
   UNBLOCKED)
  
   Thread.sleep(n)    BLOCKED        UNBLOCKED        _blockingevents()
   (n has expired on
   current thread)
  
   Interruptible I/O  BLOCKED        UNBLOCKED        _blockingevents()
   from class
   java.nio.channels
   .InterruptibleChannel
  
   Object.wait()      WAIT           NOTIFY           _wait()
   (forever on
   current thread,
   where target object
   lock was released)
  
   Object.wait(n)     WAIT           NOTIFY           _wait()
   (timed, where
   @c @b n
   has expired on
   current thread
   or target object
   lock was released)
  
   One of:            LOCK           ACQUIRE          _lock()
   Object.notify()
   Object.notifyAll()
   Thread.interrupt()
   synchronized(Object)
   ... put thread
   into LOCK state.
   Now it will
   negotiate to
   ACQUIRE its
   object's
   monitor lock.
   
  
   Thread.suspend()   ANY            BLOCKED        threadutil_suspend()
  
   Thread.resume()    BLOCKED        UNBLOCKED       threadutil_resume()
   moves a
   Thread.suspend()
   thread forward
   to UNBLOCKED
  
   

With the exception of threadutil_suspend() and threadutil_resume(), these functions is designed to be invoked from the JVM outer loop. CAVEAT EMPTOR: Those two functions are deprecated. Use at your own risk!

Todo:
Interruptible from class java.nio.channels.InterruptibleChannel
Parameters:
thridxcurr Thread for which to examine state changes
Returns:
rvoid
< This slot contains a thread

Todo:
interruptible I/O req's
< thread is sleeping

< thread is sleeping

< thread has been interrupted

< thread has been interrupted

< thread threw a java.lang.Exception (but NOT a java.lang.Error). The object type is found in pThrowableEvent and is not rnull.

Todo:
First pass guess at interruptible I/O
< thread is waiting on an interruptable I/O channel in class java.nio.channels.InterruptibleChannel

Check if Thread.interrupt() was thrown against the interruptible I/O operation on this thread.

Todo:
Is this the correct way to handle interruptible I/O events? Also need to throw the exception in JVM outer loop.
< thread has been interrupted

< thread is waiting on an interruptable I/O channel in class java.nio.channels.InterruptibleChannel

< thread has been interrupted

< thread threw a java.lang.Exception (but NOT a java.lang.Error). The object type is found in pThrowableEvent and is not rnull.

< thread has unconditionally joined another

< thread has unconditionally joined another

< thread has been interrupted

< thread has been interrupted

< thread threw a java.lang.Exception (but NOT a java.lang.Error). The object type is found in pThrowableEvent and is not rnull.

< thread has joined another, but is waiting for a finite time

< thread has joined another, but is waiting for a finite time

< thread has been interrupted

< thread has been interrupted

< thread threw a java.lang.Exception (but NOT a java.lang.Error). The object type is found in pThrowableEvent and is not rnull.

Definition at line 221 of file threadutil.c.

rvoid threadutil_update_wait jvm_thread_index  thridxcurr  ) 
 

< This slot contains a thread

< thread is unconditionally waiting

< thread has been interrupted

< thread has been interrupted

< thread threw a java.lang.Exception (but NOT a java.lang.Error). The object type is found in pThrowableEvent and is not rnull.

< thread is unconditionally waiting

< thread has been notified

< thread has been notified

< thread is unconditionally waiting

< thread is waiting, but finite time

< thread is waiting, but finite time

< thread has been interrupted

< thread has been interrupted

< thread threw a java.lang.Exception (but NOT a java.lang.Error). The object type is found in pThrowableEvent and is not rnull.

< thread is waiting, but finite time

< thread has been notified

< thread has been notified

< thread is waiting, but finite time

Definition at line 444 of file threadutil.c.

References JVMCLASS_JAVA_LANG_INTERRUPTEDEXCEPTION, THREAD, THREAD_STATUS_INTERRUPTED, THREAD_STATUS_NOTIFIED, THREAD_STATUS_THREW_EXCEPTION, THREAD_STATUS_WAITTIMED, threadstate_request_notify(), and timeslice_get_thread_sleeptime().

rvoid threadutil_update_lock jvm_thread_index  thridxcurr  ) 
 

< This slot contains a thread

< Object monitor locked by mlock_thridx

< thread is unconditionally waiting

Definition at line 575 of file threadutil.c.

rboolean threadutil_holds_lock jvm_thread_index  thridx,
jvm_object_hash  objhashlock
 

Examine an object to see if a thread owns its monitor lock.

Parameters:
thridx Thread table index of thread to compare with.
objhashlock Object table hash of object to examine.
Returns:
rtrue if this thread owns this object's monitor lock.
< This slot contains an object

< NULL object (only 1 exists in normal use, any else besides the JVMCFG_NULL_OBJECT is an object slot now being initialized.)

< This slot contains a thread

< Null thread (only 1 exists in normal use, any else besides the JVMCFG_NULL_THREAD is a thread slot that is being initialized.)

< Object monitor locked by mlock_thridx

< thread is unconditionally waiting

< thread is waiting, but finite time

Definition at line 640 of file threadutil.c.

Referenced by jlThread_interrupted().


Variable Documentation

char* threadutil_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/threadutil.c $ $Id: threadutil.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." [static]
 

Definition at line 56 of file threadutil.c.


Generated on Fri Sep 30 18:50:34 2005 by  doxygen 1.4.4