Home | History | Annotate | Download | only in lang
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package java.lang;
     18 
     19 class VMThread {
     20     Thread thread;
     21     int vmData;
     22 
     23     VMThread(Thread t) {
     24         thread = t;
     25     }
     26 
     27     native static void create(Thread t, long stackSize);
     28 
     29     static native Thread currentThread();
     30     static native boolean interrupted();
     31     static native void sleep (long msec, int nsec) throws InterruptedException;
     32     static native void yield();
     33 
     34     native void interrupt();
     35 
     36     native boolean isInterrupted();
     37 
     38     /**
     39      *  Starts the VMThread (and thus the Java Thread) with the given
     40      *  stack size.
     41      */
     42     void start(long stackSize) {
     43         VMThread.create(thread, stackSize);
     44     }
     45 
     46     /**
     47      * Queries whether this Thread holds a monitor lock on the
     48      * given object.
     49      */
     50     native boolean holdsLock(Object object);
     51 
     52     native void setPriority(int newPriority);
     53     native int getStatus();
     54 
     55     /**
     56      * Holds a mapping from native Thread statuses to Java one. Required for
     57      * translating back the result of getStatus().
     58      */
     59     static final Thread.State[] STATE_MAP = new Thread.State[] {
     60         Thread.State.TERMINATED,     // ZOMBIE
     61         Thread.State.RUNNABLE,       // RUNNING
     62         Thread.State.TIMED_WAITING,  // TIMED_WAIT
     63         Thread.State.BLOCKED,        // MONITOR
     64         Thread.State.WAITING,        // WAIT
     65         Thread.State.NEW,            // INITIALIZING
     66         Thread.State.NEW,            // STARTING
     67         Thread.State.RUNNABLE,       // NATIVE
     68         Thread.State.WAITING,        // VMWAIT
     69         Thread.State.RUNNABLE        // SUSPENDED
     70     };
     71 
     72     /**
     73      * Tell the VM that the thread's name has changed.  This is useful for
     74      * DDMS, which would otherwise be oblivious to Thread.setName calls.
     75      */
     76     native void nameChanged(String newName);
     77 }
     78