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 17package java.lang; 18 19import java.util.logging.Logger; 20import java.util.logging.Level; 21 22class VMThread 23{ 24 Thread thread; 25 int vmData; 26 27 VMThread(Thread t) { 28 thread = t; 29 } 30 31 native static void create(Thread t, long stacksize); 32 33 static native Thread currentThread(); 34 static native boolean interrupted(); 35 static native void sleep (long msec, int nsec) throws InterruptedException; 36 static native void yield(); 37 38 native void interrupt(); 39 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 */ 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") 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") 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 */ 78 native boolean holdsLock(Object object); 79 80 /** 81 * Stops the Thread, passing it a Throwable (which might be ThreadDeath). 82 */ 83 @SuppressWarnings("ThrowableInstanceNeverThrown") 84 void stop(Throwable throwable) { 85 Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD, 86 new UnsupportedOperationException()); 87 } 88 89 native void setPriority(int newPriority); 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 */ 112 native void nameChanged(String newName); 113} 114 115