jamvm

view lib/java/lang/VMThread.java @ 398:6476eceedae8

Comment out Java code that won't compile with OpenJDK's class library.

2008-08-04 Andrew John Hughes <gnu_andrew@member.fsf.org>

* lib/java/lang/VMClassLoader.java,
* lib/java/lang/VMRuntime.java,
* lib/java/lang/VMThread.java,
* lib/java/security/VMAccessController.java:
Remove GNU Classpath specific code through commenting.
author andrew
date Tue Aug 05 04:04:18 2008 +0100 (2008-08-05)
parents 09a50cebe3c3
children
line source
1 /* VMThread -- VM interface for Thread of executable code
2 Copyright (C) 2003 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.lang;
40 /**
41 * VM interface for Thread of executable code. Holds VM dependent state.
42 * It is deliberately package local and final and should only be accessed
43 * by the Thread class.
44 * <p>
45 * This is the GNU Classpath reference implementation, it should be adapted
46 * for a specific VM.
47 * <p>
48 * The following methods must be implemented:
49 * <ul>
50 * <li>native void start(long stacksize);
51 * <li>native void interrupt();
52 * <li>native boolean isInterrupted();
53 * <li>native void suspend();
54 * <li>native void resume();
55 * <li>native void nativeSetPriority(int priority);
56 * <li>native void nativeStop(Throwable t);
57 * <li>native static Thread currentThread();
58 * <li>static native void yield();
59 * <li>static native void sleep(long ms, int ns) throws InterruptedException;
60 * <li>static native boolean interrupted();
61 * <li>static native boolean holdsLock(Object obj);
62 * </ul>
63 * All other methods may be implemented to make Thread handling more efficient
64 * or to implement some optional (and sometimes deprecated) behaviour. Default
65 * implementations are provided but it is highly recommended to optimize them
66 * for a specific VM.
67 *
68 * @author Jeroen Frijters (jeroen@frijters.net)
69 */
70 final class VMThread
71 {
72 private int vmData;
74 /**
75 * The Thread object that this VM state belongs to.
76 * Used in currentThread() and start().
77 * Note: when this thread dies, this reference is *not* cleared
78 */
79 volatile Thread thread;
81 /**
82 * Creates a native Thread. This is called from the start method of Thread.
83 * The Thread is started.
84 *
85 * @param thread The newly created Thread object
86 * @param stacksize Indicates the requested stacksize. Normally zero,
87 * non-zero values indicate requested stack size in bytes but it is up
88 * to the specific VM implementation to interpret them and may be ignored.
89 */
90 static native void create(Thread thread, long stacksize);
92 /**
93 * Gets the name of the thread. Usually this is the name field of the
94 * associated Thread object, but some implementation might choose to
95 * return the name of the underlying platform thread.
96 */
97 String getName()
98 {
99 /*
100 Removed to allow building against OpenJDK
101 Andrew John Hughes - July 2008
102 return thread.name;
103 */
104 return thread.getName();
105 }
107 /**
108 * Set the name of the thread. Usually this sets the name field of the
109 * associated Thread object, but some implementations might choose to
110 * set the name of the underlying platform thread.
111 * @param name The new name
112 */
113 void setName(String name)
114 {
115 /**
116 Removed to allow building against OpenJDK
117 Andrew John Hughes - July 2008
118 thread.name = name;
119 */
120 }
122 /**
123 * Set the thread priority field in the associated Thread object and
124 * calls the native method to set the priority of the underlying
125 * platform thread.
126 * @param priority The new priority
127 */
128 void setPriority(int priority)
129 {/**
130 Removed to allow building against OpenJDK
131 Andrew John Hughes - July 2008
132 thread.priority = priority;
133 */
134 nativeSetPriority(priority);
135 }
137 /**
138 * Returns the priority. Usually this is the priority field from the
139 * associated Thread object, but some implementation might choose to
140 * return the priority of the underlying platform thread.
141 * @return this Thread's priority
142 */
143 int getPriority()
144 {
145 /*
146 Removed to allow building against OpenJDK
147 Andrew John Hughes - July 2008
148 return thread.priority;
149 */
150 return thread.getPriority();
151 }
153 /**
154 * Returns true if the thread is a daemon thread. Usually this is the
155 * daemon field from the associated Thread object, but some
156 * implementation might choose to return the daemon state of the underlying
157 * platform thread.
158 * @return whether this is a daemon Thread or not
159 */
160 boolean isDaemon()
161 {
162 /*
163 Removed to allow building against OpenJDK
164 Andrew John Hughes - July 2008
165 return thread.daemon;
166 */
167 return thread.isDaemon();
168 }
170 /**
171 * Returns the number of stack frames in this Thread.
172 * Will only be called when when a previous call to suspend() returned true.
173 *
174 * @deprecated unsafe operation
175 */
176 int countStackFrames()
177 {
178 return 0;
179 }
181 /**
182 * Wait the specified amount of time for the Thread in question to die.
183 *
184 * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
185 * not offer that fine a grain of timing resolution. Besides, there is
186 * no guarantee that this thread can start up immediately when time expires,
187 * because some other thread may be active. So don't expect real-time
188 * performance.
189 *
190 * @param ms the number of milliseconds to wait, or 0 for forever
191 * @param ns the number of extra nanoseconds to sleep (0-999999)
192 * @throws InterruptedException if the Thread is interrupted; it's
193 * <i>interrupted status</i> will be cleared
194 */
195 synchronized void join(long ms, int ns) throws InterruptedException {
196 if(thread.isAlive())
197 wait(ms, ns);
198 }
200 /**
201 * Cause this Thread to stop abnormally and throw the specified exception.
202 * If you stop a Thread that has not yet started, the stop is ignored
203 * (contrary to what the JDK documentation says).
204 * <b>WARNING</b>This bypasses Java security, and can throw a checked
205 * exception which the call stack is unprepared to handle. Do not abuse
206 * this power.
207 *
208 * <p>This is inherently unsafe, as it can interrupt synchronized blocks and
209 * leave data in bad states.
210 *
211 * <p><b>NOTE</b> stop() should take care not to stop a thread if it is
212 * executing code in this class.
213 *
214 * @param t the Throwable to throw when the Thread dies
215 * @deprecated unsafe operation, try not to use
216 */
217 void stop(Throwable t) {}
219 /**
220 * Create a native thread on the underlying platform and start it executing
221 * on the run method of this object.
222 * @param stacksize the requested size of the native thread stack
223 */
224 native void start(long stacksize);
226 /**
227 * Interrupt this thread.
228 */
229 native void interrupt();
231 /**
232 * Determine whether this Thread has been interrupted, but leave
233 * the <i>interrupted status</i> alone in the process.
234 *
235 * @return whether the Thread has been interrupted
236 */
237 native boolean isInterrupted();
239 /**
240 * Suspend this Thread. It will not come back, ever, unless it is resumed.
241 */
242 void suspend() {}
244 /**
245 * Resume this Thread. If the thread is not suspended, this method does
246 * nothing.
247 */
248 void resume() {}
250 /**
251 * Set the priority of the underlying platform thread.
252 *
253 * @param priority the new priority
254 */
255 native void nativeSetPriority(int priority);
257 /**
258 * Return the Thread object associated with the currently executing
259 * thread.
260 *
261 * @return the currently executing Thread
262 */
263 native static Thread currentThread();
265 /**
266 * Yield to another thread. The Thread will not lose any locks it holds
267 * during this time. There are no guarantees which thread will be
268 * next to run, and it could even be this one, but most VMs will choose
269 * the highest priority thread that has been waiting longest.
270 */
271 static native void yield();
273 /**
274 * Suspend the current Thread's execution for the specified amount of
275 * time. The Thread will not lose any locks it has during this time. There
276 * are no guarantees which thread will be next to run, but most VMs will
277 * choose the highest priority thread that has been waiting longest.
278 *
279 * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
280 * not offer that fine a grain of timing resolution. Besides, there is
281 * no guarantee that this thread can start up immediately when time expires,
282 * because some other thread may be active. So don't expect real-time
283 * performance.
284 *
285 * @param ms the number of milliseconds to sleep, or 0 for forever
286 * @param ns the number of extra nanoseconds to sleep (0-999999)
287 * @throws InterruptedException if the Thread is interrupted; it's
288 * <i>interrupted status</i> will be cleared
289 * @throws IllegalArgumentException if ns is invalid
290 */
291 static native void sleep(long ms, int ns) throws InterruptedException;
293 /**
294 * Determine whether the current Thread has been interrupted, and clear
295 * the <i>interrupted status</i> in the process.
296 *
297 * @return whether the current Thread has been interrupted
298 */
299 static native boolean interrupted();
301 /**
302 * Checks whether the current thread holds the monitor on a given object.
303 * This allows you to do <code>assert Thread.holdsLock(obj)</code>.
304 *
305 * @param obj the object to check
306 * @return true if the current thread is currently synchronized on obj
307 * @throws NullPointerException if obj is null
308 */
309 static native boolean holdsLock(Object obj);
312 /**
313 * Returns the current state of the thread.
314 * The value must be one of "BLOCKED", "NEW",
315 * "RUNNABLE", "TERMINATED", "TIMED_WAITING" or
316 * "WAITING".
317 *
318 * @return a string corresponding to one of the
319 * thread enumeration states specified above.
320 */
321 native String getState();
322 }