• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.util.logging.Logger;
20 import java.util.logging.Level;
21 
22 class VMThread
23 {
24     Thread thread;
25     int vmData;
26 
VMThread(Thread t)27     VMThread(Thread t) {
28         thread = t;
29     }
30 
create(Thread t, long stacksize)31     native static void create(Thread t, long stacksize);
32 
currentThread()33     static native Thread currentThread();
interrupted()34     static native boolean interrupted();
sleep(long msec, int nsec)35     static native void sleep (long msec, int nsec) throws InterruptedException;
yield()36     static native void yield();
37 
interrupt()38     native void interrupt();
39 
isInterrupted()40     native boolean isInterrupted();
41 
42     /**
43      *  Starts the VMThread (and thus the Java Thread) with the given
44      *  stacksize.
45      *
46      * @param stacksize
47      *                 The desired stacksize.
48      */
start(long stacksize)49     void start(long stacksize) {
50         VMThread.create(thread, stacksize);
51     }
52 
53     private static final String UNSUPPORTED_THREAD_METHOD
54             = "Deprecated Thread methods are not supported.";
55 
56     /**
57      * Suspends the Thread.
58      */
59     @SuppressWarnings("ThrowableInstanceNeverThrown")
suspend()60     void suspend() {
61         Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD,
62                 new UnsupportedOperationException());
63     }
64 
65     /**
66      * Resumes the Thread, assuming it is suspended.
67      */
68     @SuppressWarnings("ThrowableInstanceNeverThrown")
resume()69     void resume() {
70         Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD,
71                 new UnsupportedOperationException());
72     }
73 
74     /**
75      * Queries whether this Thread holds a monitor lock on the
76      * given object.
77      */
holdsLock(Object object)78     native boolean holdsLock(Object object);
79 
80     /**
81      * Stops the Thread, passing it a Throwable (which might be ThreadDeath).
82      */
83     @SuppressWarnings("ThrowableInstanceNeverThrown")
stop(Throwable throwable)84     void stop(Throwable throwable) {
85         Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD,
86                 new UnsupportedOperationException());
87     }
88 
setPriority(int newPriority)89     native void setPriority(int newPriority);
getStatus()90     native int getStatus();
91 
92     /**
93      * Holds a mapping from native Thread statii to Java one. Required for
94      * translating back the result of getStatus().
95      */
96     static final Thread.State[] STATE_MAP = new Thread.State[] {
97         Thread.State.TERMINATED,     // ZOMBIE
98         Thread.State.RUNNABLE,       // RUNNING
99         Thread.State.TIMED_WAITING,  // TIMED_WAIT
100         Thread.State.BLOCKED,        // MONITOR
101         Thread.State.WAITING,        // WAIT
102         Thread.State.NEW,            // INITIALIZING
103         Thread.State.NEW,            // STARTING
104         Thread.State.RUNNABLE,       // NATIVE
105         Thread.State.WAITING         // VMWAIT
106     };
107 
108     /**
109      * Tell the VM that the thread's name has changed.  This is useful for
110      * DDMS, which would otherwise be oblivious to Thread.setName calls.
111      */
nameChanged(String newName)112     native void nameChanged(String newName);
113 }
114 
115