1 |
/* VMObject.java |
/* VMObject.java -- Reference implementation for VM hooks used by Object |
2 |
Copyright (C) 1998 Free Software Foundation |
Copyright (C) 1998, 2002 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
38 |
package java.lang; |
package java.lang; |
39 |
|
|
40 |
/** |
/** |
41 |
** Object is the ultimate superclass of every class |
* Object is the ultimate superclass of every class (excepting interfaces). |
42 |
** (excepting interfaces). When you define a class that |
* As such, it needs help from the VM. |
43 |
** does not extend any other class, it implicitly extends |
* |
44 |
** java.lang.Object. |
* @author John Keiser |
45 |
** |
* @author Eric Blake <ebb9@email.byu.edu> |
46 |
** It provides general-purpose methods that every single |
*/ |
47 |
** Object, regardless of race, sex or creed, implements. |
final class VMObject |
48 |
** |
{ |
49 |
** @author John Keiser |
/** |
50 |
** @version 1.1.0, Aug 6 1998 |
* The VM is expected to make a field-for-field shallow copy of the |
51 |
**/ |
* argument. Thus, the copy has the same runtime type as the argument. |
52 |
|
* Note, however, that the cloned object must still be finalizable, even |
53 |
class VMObject { |
* if the original has already had finalize() invoked on it. |
54 |
/** This method may be called to create a new copy of the |
* |
55 |
** Object. However, there are *no* requirements at all |
* @param c the Cloneable to clone |
56 |
** placed on this method, just suggestions. The ==, |
* @return the clone |
57 |
** equals() and instanceof comparisons may even return |
*/ |
58 |
** false when comparing the original with the clone!<P> |
static native Object clone(Cloneable c); |
59 |
** |
|
60 |
** If the Object you call clone() on does not implement |
/** |
61 |
** Cloneable (which is a placeholder interface), then |
* Returns the class of this Object as a Class object. |
62 |
** a CloneNotSupportedException is thrown.<P> |
* |
63 |
** |
* @param o the object to look up |
64 |
** Object's implementation of clone allocates space for |
* @return the class of this Object |
65 |
** the new Object using the correct class, and then fills |
*/ |
66 |
** in all of the new field values with the old field |
static native Class getClass(Object o); |
67 |
** values. Thus, it is a shallow copy. |
|
68 |
** |
/** |
69 |
** @exception CloneNotSupportedException |
* Wakes up one of the threads that is waiting on this Object's monitor. |
70 |
** @return a copy of the Object. |
* Only the owner of a lock on the Object may call this method. The Thread |
71 |
**/ |
* to wake up is chosen arbitrarily. |
72 |
static native Object clone(Object o) throws CloneNotSupportedException; |
* |
73 |
|
* @param o the object doing the notify |
74 |
/** Returns the class of this Object as a Class object. |
* @throw IllegalMonitorStateException if this Thread does not own the |
75 |
** @return the class of this Object. |
* lock on the Object |
76 |
** @see java.lang.Class |
*/ |
77 |
**/ |
static native void notify(Object o) throws IllegalMonitorStateException; |
78 |
static native Class getClass(Object o); |
|
79 |
|
/** |
80 |
/** Wakes up one of the threads that is waiting on this |
* Wakes up all of the threads waiting on this Object's monitor. Only |
81 |
** Object's monitor. Only the owner of a lock on the |
* the owner of the lock on this Object may call this method. |
82 |
** Object may call this method.<P> |
* |
83 |
** |
* @param o the object doing the notifyAll |
84 |
** The Thread to wake up is chosen arbitrarily.<P> |
* @throws IllegalMonitorStateException if this Thread does not own the |
85 |
** |
* lock on the Object |
86 |
** If the Thread waiting on this Object is waiting |
*/ |
87 |
** because it wants to obtain the lock, then the notify() |
static native void notifyAll(Object o) throws IllegalMonitorStateException; |
88 |
** call will in essence do nothing, since the lock will |
|
89 |
** still be owned by the Thread that called notify(). |
/** |
90 |
** |
* Waits a specified amount of time for notify() or notifyAll() to be |
91 |
** @exception IllegalMonitorStateException if this Thread |
* called on this Object. The VM does not have to pay attention to the |
92 |
** does not own the lock on the Object. |
* ns argument, if it does not have that much granularity. |
93 |
**/ |
* |
94 |
static native void notify(Object o) throws IllegalMonitorStateException; |
* @param o the object to suspend on |
95 |
|
* @param ms milliseconds to wait (1,000 milliseconds = 1 second) |
96 |
/** Wakes up all of the threads waiting on this Object's |
* @param ns nanoseconds to wait beyond ms (1,000,000 nanoseconds |
97 |
** monitor. Only the owner of the lock on this Object |
* == 1 millisecond) |
98 |
** may call this method.<P> |
* @throws IllegalMonitorStateException if this Thread does not own the |
99 |
** |
* lock on the Object |
100 |
** If the Threads waiting on this Object are waiting |
* @throws InterruptedException if some other Thread interrupts this Thread |
101 |
** because they want to obtain the lock, then the |
*/ |
102 |
** notifyAll() call will in essence do nothing, since the |
static native void wait(Object o, long ms, int ns) |
103 |
** lock will still be owned by the Thread that called |
throws IllegalMonitorStateException, InterruptedException; |
|
** notifyAll(). |
|
|
** |
|
|
** @exception IllegalMonitorStateException if this Thread |
|
|
** does not own the lock on the Object. |
|
|
**/ |
|
|
static native void notifyAll(Object o) throws IllegalMonitorStateException; |
|
|
|
|
|
/** Waits a specified amount of time for notify() or |
|
|
** notifyAll() to be called on this Object. This call |
|
|
** behaves almost identically to wait(int ms), except it |
|
|
** throws nanoseconds into the pot. It's fairly useless, |
|
|
** though; if we can only roughly estimate the number of |
|
|
** milliseconds to wait, how do you think we can exactly |
|
|
** deal with nanoseconds? |
|
|
** @param ms the number of milliseconds to wait (1,000 |
|
|
** milliseconds = 1 second). |
|
|
** @param ns the number of nanoseconds to wait over and |
|
|
** above ms (1,000,000 nanoseconds = 1 second). |
|
|
** @exception IllegalMonitorStateException if this Thread |
|
|
** does not own a lock on this Object. |
|
|
** @exception InterruptedException if some other Thread |
|
|
** interrupts this Thread. |
|
|
**/ |
|
|
static native void wait(Object o,long ms, int ns) throws IllegalMonitorStateException, InterruptedException; |
|
104 |
} |
} |