下载 VMThread.java
001 | /** |
002 | * Copyright (C) 2007 The Android Open Source Project |
003 | * |
004 | * Licensed under the Apache License, Version 2.0 (the "License"); |
005 | * you may not use this file except in compliance with the License. |
006 | * You may obtain a copy of the License at |
007 | * |
008 | * http://www.apache.org/licenses/LICENSE-2.0 |
009 | * |
010 | * Unless required by applicable law or agreed to in writing, software |
011 | * distributed under the License is distributed on an "AS IS" BASIS, |
012 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
013 | * See the License for the specific language governing permissions and |
014 | * limitations under the License. |
015 | */ |
016 |
017 | package java.lang; |
018 |
019 | import java.util.logging.Logger; |
020 | import java.util.logging.Level; |
021 |
022 | class VMThread |
023 | { |
024 | Thread thread; |
025 | int vmData; |
026 |
027 | VMThread(Thread t) { |
028 | thread = t; |
029 | } |
030 |
031 | native static void create(Thread t, long stacksize); |
032 |
033 | static native Thread currentThread(); |
034 | static native boolean interrupted(); |
035 | static native void sleep ( long msec, int nsec) throws InterruptedException; |
036 | static native void yield(); |
037 |
038 | native void interrupt(); |
039 |
040 | native boolean isInterrupted(); |
041 |
042 | /*** |
043 | * Starts the VMThread (and thus the Java Thread) with the given |
044 | * stacksize. |
045 | * |
046 | * @param stacksize |
047 | * The desired stacksize. |
048 | */ |
049 | void start( long stacksize) { |
050 | VMThread.create(thread, stacksize); |
051 | } |
052 |
053 | private static final String UNSUPPORTED_THREAD_METHOD |
054 | = "Deprecated Thread methods are not supported." ; |
055 |
056 | /*** |
057 | * Suspends the Thread. |
058 | */ |
059 | @SuppressWarnings ( "ThrowableInstanceNeverThrown" ) |
060 | void suspend() { |
061 | Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD, |
062 | new UnsupportedOperationException()); |
063 | } |
064 |
065 | /*** |
066 | * Resumes the Thread, assuming it is suspended. |
067 | */ |
068 | @SuppressWarnings ( "ThrowableInstanceNeverThrown" ) |
069 | void resume() { |
070 | Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD, |
071 | new UnsupportedOperationException()); |
072 | } |
073 |
074 | /*** |
075 | * Queries whether this Thread holds a monitor lock on the |
076 | * given object. |
077 | */ |
078 | native boolean holdsLock(Object object); |
079 |
080 | /*** |
081 | * Stops the Thread, passing it a Throwable (which might be ThreadDeath). |
082 | */ |
083 | @SuppressWarnings ( "ThrowableInstanceNeverThrown" ) |
084 | void stop(Throwable throwable) { |
085 | Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD, |
086 | new UnsupportedOperationException()); |
087 | } |
088 |
089 | native void setPriority( int newPriority); |
090 | native int getStatus(); |
091 |
092 | /*** |
093 | * Holds a mapping from native Thread statii to Java one. Required for |
094 | * translating back the result of getStatus(). |
095 | */ |
096 | static final Thread.State[] STATE_MAP = new Thread.State[] { |
097 | Thread.State.TERMINATED, // ZOMBIE |
098 | Thread.State.RUNNABLE, // RUNNING |
099 | 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 | } |