Mercurial > hg > release > icedtea7-2.1
changeset 1571:dbdaa8e2cf1f
Fix some sun.nio.ch classes.
2009-01-14 Andrew John Hughes <gnu_andrew@member.fsf.org>
* overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/nio/channels/FileChannel.java:
Extend java.nio.channels.FileChannel to minimise code.
* overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/util/concurrent/ScheduledThreadPoolExecutor.java:
Adapted to use the SharedSecrets backdoor.
* overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/misc/JavaUtilConcurrentThreadPoolExecutorAccess.java:
Add remaining methods needed for our ScheduledThreadPoolExecutor.
* overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java:
Create a ScheduledThreadPoolExecutor directly so ours is used.
* overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java:
Refer to AsynchronousFileLockImpl not FileLockImpl.
* overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileLockImpl.java,
* overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/FileLockTable.java:
Fix imports.
* patches/icedtea-nio2.patch:
Update implementation of secrets interface.
author | Andrew John Hughes <gnu_andrew@member.fsf.org> |
---|---|
date | Thu, 15 Jan 2009 02:31:47 +0000 |
parents | 9eb9c1670c99 |
children | 585bc814cee8 |
files | ChangeLog overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/nio/channels/FileChannel.java overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/util/concurrent/ScheduledThreadPoolExecutor.java overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/misc/JavaUtilConcurrentThreadPoolExecutorAccess.java overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileLockImpl.java overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/FileLockTable.java patches/icedtea-nio2.patch |
diffstat | 9 files changed, 86 insertions(+), 797 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Jan 14 05:29:15 2009 +0000 +++ b/ChangeLog Thu Jan 15 02:31:47 2009 +0000 @@ -1,3 +1,21 @@ +2009-01-14 Andrew John Hughes <gnu_andrew@member.fsf.org> + + * overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/nio/channels/FileChannel.java: + Extend java.nio.channels.FileChannel to minimise code. + * overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/util/concurrent/ScheduledThreadPoolExecutor.java: + Adapted to use the SharedSecrets backdoor. + * overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/misc/JavaUtilConcurrentThreadPoolExecutorAccess.java: + Add remaining methods needed for our ScheduledThreadPoolExecutor. + * overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java: + Create a ScheduledThreadPoolExecutor directly so ours is used. + * overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java: + Refer to AsynchronousFileLockImpl not FileLockImpl. + * overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileLockImpl.java, + * overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/FileLockTable.java: + Fix imports. + * patches/icedtea-nio2.patch: + Update implementation of secrets interface. + 2009-01-13 Andrew John Hughes <gnu_andrew@member.fsf.org> * overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/misc/JavaIODeleteOnExitAccess.java,
--- a/overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/nio/channels/FileChannel.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/nio/channels/FileChannel.java Thu Jan 15 02:31:47 2009 +0000 @@ -162,8 +162,8 @@ */ public abstract class FileChannel - extends AbstractInterruptibleChannel - implements SeekableByteChannel, GatheringByteChannel, ScatteringByteChannel + extends java.nio.channels.FileChannel + implements SeekableByteChannel { /** * Initializes a new instance of this class. @@ -288,9 +288,9 @@ * * @since 1.7 */ - public static FileChannel open(Path file, - Set<? extends OpenOption> options, - FileAttribute<?>... attrs) + public static java.nio.channels.FileChannel open(Path file, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) throws IOException { FileSystemProvider provider = file.getFileSystem().provider(); @@ -335,7 +335,7 @@ * * @since 1.7 */ - public static FileChannel open(Path file, OpenOption... options) + public static java.nio.channels.FileChannel open(Path file, OpenOption... options) throws IOException { Set<OpenOption> set = new HashSet<OpenOption>(options.length); @@ -343,103 +343,6 @@ return open(file, set, NO_ATTRIBUTES); } - // -- Channel operations -- - - /** - * Reads a sequence of bytes from this channel into the given buffer. - * - * <p> Bytes are read starting at this channel's current file position, and - * then the file position is updated with the number of bytes actually - * read. Otherwise this method behaves exactly as specified in the {@link - * ReadableByteChannel} interface. </p> - */ - public abstract int read(ByteBuffer dst) throws IOException; - - /** - * Reads a sequence of bytes from this channel into a subsequence of the - * given buffers. - * - * <p> Bytes are read starting at this channel's current file position, and - * then the file position is updated with the number of bytes actually - * read. Otherwise this method behaves exactly as specified in the {@link - * ScatteringByteChannel} interface. </p> - */ - public abstract long read(ByteBuffer[] dsts, int offset, int length) - throws IOException; - - /** - * Reads a sequence of bytes from this channel into the given buffers. - * - * <p> Bytes are read starting at this channel's current file position, and - * then the file position is updated with the number of bytes actually - * read. Otherwise this method behaves exactly as specified in the {@link - * ScatteringByteChannel} interface. </p> - */ - public final long read(ByteBuffer[] dsts) throws IOException { - return read(dsts, 0, dsts.length); - } - - /** - * Writes a sequence of bytes to this channel from the given buffer. - * - * <p> Bytes are written starting at this channel's current file position - * unless the channel is in append mode, in which case the position is - * first advanced to the end of the file. The file is grown, if necessary, - * to accommodate the written bytes, and then the file position is updated - * with the number of bytes actually written. Otherwise this method - * behaves exactly as specified by the {@link WritableByteChannel} - * interface. </p> - */ - public abstract int write(ByteBuffer src) throws IOException; - - /** - * Writes a sequence of bytes to this channel from a subsequence of the - * given buffers. - * - * <p> Bytes are written starting at this channel's current file position - * unless the channel is in append mode, in which case the position is - * first advanced to the end of the file. The file is grown, if necessary, - * to accommodate the written bytes, and then the file position is updated - * with the number of bytes actually written. Otherwise this method - * behaves exactly as specified in the {@link GatheringByteChannel} - * interface. </p> - */ - public abstract long write(ByteBuffer[] srcs, int offset, int length) - throws IOException; - - /** - * Writes a sequence of bytes to this channel from the given buffers. - * - * <p> Bytes are written starting at this channel's current file position - * unless the channel is in append mode, in which case the position is - * first advanced to the end of the file. The file is grown, if necessary, - * to accommodate the written bytes, and then the file position is updated - * with the number of bytes actually written. Otherwise this method - * behaves exactly as specified in the {@link GatheringByteChannel} - * interface. </p> - */ - public final long write(ByteBuffer[] srcs) throws IOException { - return write(srcs, 0, srcs.length); - } - - - // -- Other operations -- - - /** - * Returns this channel's file position. </p> - * - * @return This channel's file position, - * a non-negative integer counting the number of bytes - * from the beginning of the file to the current position - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract long position() throws IOException; - /** * Sets this channel's file position. * @@ -469,20 +372,6 @@ public abstract FileChannel position(long newPosition) throws IOException; /** - * Returns the current size of this channel's file. </p> - * - * @return The current size of this channel's file, - * measured in bytes - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract long size() throws IOException; - - /** * Truncates this channel's file to the given size. * * <p> If the given size is less than the file's current size then the file @@ -511,656 +400,5 @@ */ public abstract FileChannel truncate(long size) throws IOException; - /** - * Forces any updates to this channel's file to be written to the storage - * device that contains it. - * - * <p> If this channel's file resides on a local storage device then when - * this method returns it is guaranteed that all changes made to the file - * since this channel was created, or since this method was last invoked, - * will have been written to that device. This is useful for ensuring that - * critical information is not lost in the event of a system crash. - * - * <p> If the file does not reside on a local device then no such guarantee - * is made. - * - * <p> The <tt>metaData</tt> parameter can be used to limit the number of - * I/O operations that this method is required to perform. Passing - * <tt>false</tt> for this parameter indicates that only updates to the - * file's content need be written to storage; passing <tt>true</tt> - * indicates that updates to both the file's content and metadata must be - * written, which generally requires at least one more I/O operation. - * Whether this parameter actually has any effect is dependent upon the - * underlying operating system and is therefore unspecified. - * - * <p> Invoking this method may cause an I/O operation to occur even if the - * channel was only opened for reading. Some operating systems, for - * example, maintain a last-access time as part of a file's metadata, and - * this time is updated whenever the file is read. Whether or not this is - * actually done is system-dependent and is therefore unspecified. - * - * <p> This method is only guaranteed to force changes that were made to - * this channel's file via the methods defined in this class. It may or - * may not force changes that were made by modifying the content of a - * {@link MappedByteBuffer <i>mapped byte buffer</i>} obtained by - * invoking the {@link #map map} method. Invoking the {@link - * MappedByteBuffer#force force} method of the mapped byte buffer will - * force changes made to the buffer's content to be written. </p> - * - * @param metaData - * If <tt>true</tt> then this method is required to force changes - * to both the file's content and metadata to be written to - * storage; otherwise, it need only force content changes to be - * written - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract void force(boolean metaData) throws IOException; - - /** - * Transfers bytes from this channel's file to the given writable byte - * channel. - * - * <p> An attempt is made to read up to <tt>count</tt> bytes starting at - * the given <tt>position</tt> in this channel's file and write them to the - * target channel. An invocation of this method may or may not transfer - * all of the requested bytes; whether or not it does so depends upon the - * natures and states of the channels. Fewer than the requested number of - * bytes are transferred if this channel's file contains fewer than - * <tt>count</tt> bytes starting at the given <tt>position</tt>, or if the - * target channel is non-blocking and it has fewer than <tt>count</tt> - * bytes free in its output buffer. - * - * <p> This method does not modify this channel's position. If the given - * position is greater than the file's current size then no bytes are - * transferred. If the target channel has a position then bytes are - * written starting at that position and then the position is incremented - * by the number of bytes written. - * - * <p> This method is potentially much more efficient than a simple loop - * that reads from this channel and writes to the target channel. Many - * operating systems can transfer bytes directly from the filesystem cache - * to the target channel without actually copying them. </p> - * - * @param position - * The position within the file at which the transfer is to begin; - * must be non-negative - * - * @param count - * The maximum number of bytes to be transferred; must be - * non-negative - * - * @param target - * The target channel - * - * @return The number of bytes, possibly zero, - * that were actually transferred - * - * @throws IllegalArgumentException - * If the preconditions on the parameters do not hold - * - * @throws NonReadableChannelException - * If this channel was not opened for reading - * - * @throws NonWritableChannelException - * If the target channel was not opened for writing - * - * @throws ClosedChannelException - * If either this channel or the target channel is closed - * - * @throws AsynchronousCloseException - * If another thread closes either channel - * while the transfer is in progress - * - * @throws ClosedByInterruptException - * If another thread interrupts the current thread while the - * transfer is in progress, thereby closing both channels and - * setting the current thread's interrupt status - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract long transferTo(long position, long count, - WritableByteChannel target) - throws IOException; - - /** - * Transfers bytes into this channel's file from the given readable byte - * channel. - * - * <p> An attempt is made to read up to <tt>count</tt> bytes from the - * source channel and write them to this channel's file starting at the - * given <tt>position</tt>. An invocation of this method may or may not - * transfer all of the requested bytes; whether or not it does so depends - * upon the natures and states of the channels. Fewer than the requested - * number of bytes will be transferred if the source channel has fewer than - * <tt>count</tt> bytes remaining, or if the source channel is non-blocking - * and has fewer than <tt>count</tt> bytes immediately available in its - * input buffer. - * - * <p> This method does not modify this channel's position. If the given - * position is greater than the file's current size then no bytes are - * transferred. If the source channel has a position then bytes are read - * starting at that position and then the position is incremented by the - * number of bytes read. - * - * <p> This method is potentially much more efficient than a simple loop - * that reads from the source channel and writes to this channel. Many - * operating systems can transfer bytes directly from the source channel - * into the filesystem cache without actually copying them. </p> - * - * @param src - * The source channel - * - * @param position - * The position within the file at which the transfer is to begin; - * must be non-negative - * - * @param count - * The maximum number of bytes to be transferred; must be - * non-negative - * - * @return The number of bytes, possibly zero, - * that were actually transferred - * - * @throws IllegalArgumentException - * If the preconditions on the parameters do not hold - * - * @throws NonReadableChannelException - * If the source channel was not opened for reading - * - * @throws NonWritableChannelException - * If this channel was not opened for writing - * - * @throws ClosedChannelException - * If either this channel or the source channel is closed - * - * @throws AsynchronousCloseException - * If another thread closes either channel - * while the transfer is in progress - * - * @throws ClosedByInterruptException - * If another thread interrupts the current thread while the - * transfer is in progress, thereby closing both channels and - * setting the current thread's interrupt status - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract long transferFrom(ReadableByteChannel src, - long position, long count) - throws IOException; - - /** - * Reads a sequence of bytes from this channel into the given buffer, - * starting at the given file position. - * - * <p> This method works in the same manner as the {@link - * #read(ByteBuffer)} method, except that bytes are read starting at the - * given file position rather than at the channel's current position. This - * method does not modify this channel's position. If the given position - * is greater than the file's current size then no bytes are read. </p> - * - * @param dst - * The buffer into which bytes are to be transferred - * - * @param position - * The file position at which the transfer is to begin; - * must be non-negative - * - * @return The number of bytes read, possibly zero, or <tt>-1</tt> if the - * given position is greater than or equal to the file's current - * size - * - * @throws IllegalArgumentException - * If the position is negative - * - * @throws NonReadableChannelException - * If this channel was not opened for reading - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws AsynchronousCloseException - * If another thread closes this channel - * while the read operation is in progress - * - * @throws ClosedByInterruptException - * If another thread interrupts the current thread - * while the read operation is in progress, thereby - * closing the channel and setting the current thread's - * interrupt status - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract int read(ByteBuffer dst, long position) throws IOException; - - /** - * Writes a sequence of bytes to this channel from the given buffer, - * starting at the given file position. - * - * <p> This method works in the same manner as the {@link - * #write(ByteBuffer)} method, except that bytes are written starting at - * the given file position rather than at the channel's current position. - * This method does not modify this channel's position. If the given - * position is greater than the file's current size then the file will be - * grown to accommodate the new bytes; the values of any bytes between the - * previous end-of-file and the newly-written bytes are unspecified. </p> - * - * @param src - * The buffer from which bytes are to be transferred - * - * @param position - * The file position at which the transfer is to begin; - * must be non-negative - * - * @return The number of bytes written, possibly zero - * - * @throws IllegalArgumentException - * If the position is negative - * - * @throws NonWritableChannelException - * If this channel was not opened for writing - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws AsynchronousCloseException - * If another thread closes this channel - * while the write operation is in progress - * - * @throws ClosedByInterruptException - * If another thread interrupts the current thread - * while the write operation is in progress, thereby - * closing the channel and setting the current thread's - * interrupt status - * - * @throws IOException - * If some other I/O error occurs - */ - public abstract int write(ByteBuffer src, long position) throws IOException; - - - // -- Memory-mapped buffers -- - - /** - * A typesafe enumeration for file-mapping modes. - * - * @since 1.4 - * - * @see java.nio.channels.FileChannel#map - */ - public static class MapMode { - - /** - * Mode for a read-only mapping. - */ - public static final MapMode READ_ONLY - = new MapMode("READ_ONLY"); - - /** - * Mode for a read/write mapping. - */ - public static final MapMode READ_WRITE - = new MapMode("READ_WRITE"); - - /** - * Mode for a private (copy-on-write) mapping. - */ - public static final MapMode PRIVATE - = new MapMode("PRIVATE"); - - private final String name; - - private MapMode(String name) { - this.name = name; - } - - /** - * Returns a string describing this file-mapping mode. - * - * @return A descriptive string - */ - public String toString() { - return name; - } - - } - - /** - * Maps a region of this channel's file directly into memory. - * - * <p> A region of a file may be mapped into memory in one of three modes: - * </p> - * - * <ul type=disc> - * - * <li><p> <i>Read-only:</i> Any attempt to modify the resulting buffer - * will cause a {@link java.nio.ReadOnlyBufferException} to be thrown. - * ({@link MapMode#READ_ONLY MapMode.READ_ONLY}) </p></li> - * - * <li><p> <i>Read/write:</i> Changes made to the resulting buffer will - * eventually be propagated to the file; they may or may not be made - * visible to other programs that have mapped the same file. ({@link - * MapMode#READ_WRITE MapMode.READ_WRITE}) </p></li> - * - * <li><p> <i>Private:</i> Changes made to the resulting buffer will not - * be propagated to the file and will not be visible to other programs - * that have mapped the same file; instead, they will cause private - * copies of the modified portions of the buffer to be created. ({@link - * MapMode#PRIVATE MapMode.PRIVATE}) </p></li> - * - * </ul> - * - * <p> For a read-only mapping, this channel must have been opened for - * reading; for a read/write or private mapping, this channel must have - * been opened for both reading and writing. - * - * <p> The {@link MappedByteBuffer <i>mapped byte buffer</i>} - * returned by this method will have a position of zero and a limit and - * capacity of <tt>size</tt>; its mark will be undefined. The buffer and - * the mapping that it represents will remain valid until the buffer itself - * is garbage-collected. - * - * <p> A mapping, once established, is not dependent upon the file channel - * that was used to create it. Closing the channel, in particular, has no - * effect upon the validity of the mapping. - * - * <p> Many of the details of memory-mapped files are inherently dependent - * upon the underlying operating system and are therefore unspecified. The - * behavior of this method when the requested region is not completely - * contained within this channel's file is unspecified. Whether changes - * made to the content or size of the underlying file, by this program or - * another, are propagated to the buffer is unspecified. The rate at which - * changes to the buffer are propagated to the file is unspecified. - * - * <p> For most operating systems, mapping a file into memory is more - * expensive than reading or writing a few tens of kilobytes of data via - * the usual {@link #read read} and {@link #write write} methods. From the - * standpoint of performance it is generally only worth mapping relatively - * large files into memory. </p> - * - * @param mode - * One of the constants {@link MapMode#READ_ONLY READ_ONLY}, {@link - * MapMode#READ_WRITE READ_WRITE}, or {@link MapMode#PRIVATE - * PRIVATE} defined in the {@link MapMode} class, according to - * whether the file is to be mapped read-only, read/write, or - * privately (copy-on-write), respectively - * - * @param position - * The position within the file at which the mapped region - * is to start; must be non-negative - * - * @param size - * The size of the region to be mapped; must be non-negative and - * no greater than {@link java.lang.Integer#MAX_VALUE} - * - * @return The mapped byte buffer - * - * @throws NonReadableChannelException - * If the <tt>mode</tt> is {@link MapMode#READ_ONLY READ_ONLY} but - * this channel was not opened for reading - * - * @throws NonWritableChannelException - * If the <tt>mode</tt> is {@link MapMode#READ_WRITE READ_WRITE} or - * {@link MapMode#PRIVATE PRIVATE} but this channel was not opened - * for both reading and writing - * - * @throws IllegalArgumentException - * If the preconditions on the parameters do not hold - * - * @throws IOException - * If some other I/O error occurs - * - * @see java.nio.channels.FileChannel.MapMode - * @see java.nio.MappedByteBuffer - */ - public abstract MappedByteBuffer map(MapMode mode, - long position, long size) - throws IOException; - - - // -- Locks -- - - /** - * Acquires a lock on the given region of this channel's file. - * - * <p> An invocation of this method will block until the region can be - * locked, this channel is closed, or the invoking thread is interrupted, - * whichever comes first. - * - * <p> If this channel is closed by another thread during an invocation of - * this method then an {@link AsynchronousCloseException} will be thrown. - * - * <p> If the invoking thread is interrupted while waiting to acquire the - * lock then its interrupt status will be set and a {@link - * FileLockInterruptionException} will be thrown. If the invoker's - * interrupt status is set when this method is invoked then that exception - * will be thrown immediately; the thread's interrupt status will not be - * changed. - * - * <p> The region specified by the <tt>position</tt> and <tt>size</tt> - * parameters need not be contained within, or even overlap, the actual - * underlying file. Lock regions are fixed in size; if a locked region - * initially contains the end of the file and the file grows beyond the - * region then the new portion of the file will not be covered by the lock. - * If a file is expected to grow in size and a lock on the entire file is - * required then a region starting at zero, and no smaller than the - * expected maximum size of the file, should be locked. The zero-argument - * {@link #lock()} method simply locks a region of size {@link - * Long#MAX_VALUE}. - * - * <p> Some operating systems do not support shared locks, in which case a - * request for a shared lock is automatically converted into a request for - * an exclusive lock. Whether the newly-acquired lock is shared or - * exclusive may be tested by invoking the resulting lock object's {@link - * FileLock#isShared() isShared} method. - * - * <p> File locks are held on behalf of the entire Java virtual machine. - * They are not suitable for controlling access to a file by multiple - * threads within the same virtual machine. </p> - * - * @param position - * The position at which the locked region is to start; must be - * non-negative - * - * @param size - * The size of the locked region; must be non-negative, and the sum - * <tt>position</tt> + <tt>size</tt> must be non-negative - * - * @param shared - * <tt>true</tt> to request a shared lock, in which case this - * channel must be open for reading (and possibly writing); - * <tt>false</tt> to request an exclusive lock, in which case this - * channel must be open for writing (and possibly reading) - * - * @return A lock object representing the newly-acquired lock - * - * @throws IllegalArgumentException - * If the preconditions on the parameters do not hold - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws AsynchronousCloseException - * If another thread closes this channel while the invoking - * thread is blocked in this method - * - * @throws FileLockInterruptionException - * If the invoking thread is interrupted while blocked in this - * method - * - * @throws OverlappingFileLockException - * If a lock that overlaps the requested region is already held by - * this Java virtual machine, or if another thread is already - * blocked in this method and is attempting to lock an overlapping - * region - * - * @throws NonReadableChannelException - * If <tt>shared</tt> is <tt>true</tt> this channel was not - * opened for reading - * - * @throws NonWritableChannelException - * If <tt>shared</tt> is <tt>false</tt> but this channel was not - * opened for writing - * - * @throws IOException - * If some other I/O error occurs - * - * @see #lock() - * @see #tryLock() - * @see #tryLock(long,long,boolean) - */ - public abstract FileLock lock(long position, long size, boolean shared) - throws IOException; - - /** - * Acquires an exclusive lock on this channel's file. - * - * <p> An invocation of this method of the form <tt>fc.lock()</tt> behaves - * in exactly the same way as the invocation - * - * <pre> - * fc.{@link #lock(long,long,boolean) lock}(0L, Long.MAX_VALUE, false) </pre> - * - * @return A lock object representing the newly-acquired lock - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws AsynchronousCloseException - * If another thread closes this channel while the invoking - * thread is blocked in this method - * - * @throws FileLockInterruptionException - * If the invoking thread is interrupted while blocked in this - * method - * - * @throws OverlappingFileLockException - * If a lock that overlaps the requested region is already held by - * this Java virtual machine, or if another thread is already - * blocked in this method and is attempting to lock an overlapping - * region of the same file - * - * @throws NonWritableChannelException - * If this channel was not opened for writing - * - * @throws IOException - * If some other I/O error occurs - * - * @see #lock(long,long,boolean) - * @see #tryLock() - * @see #tryLock(long,long,boolean) - */ - public final FileLock lock() throws IOException { - return lock(0L, Long.MAX_VALUE, false); - } - - /** - * Attempts to acquire a lock on the given region of this channel's file. - * - * <p> This method does not block. An invocation always returns - * immediately, either having acquired a lock on the requested region or - * having failed to do so. If it fails to acquire a lock because an - * overlapping lock is held by another program then it returns - * <tt>null</tt>. If it fails to acquire a lock for any other reason then - * an appropriate exception is thrown. - * - * <p> The region specified by the <tt>position</tt> and <tt>size</tt> - * parameters need not be contained within, or even overlap, the actual - * underlying file. Lock regions are fixed in size; if a locked region - * initially contains the end of the file and the file grows beyond the - * region then the new portion of the file will not be covered by the lock. - * If a file is expected to grow in size and a lock on the entire file is - * required then a region starting at zero, and no smaller than the - * expected maximum size of the file, should be locked. The zero-argument - * {@link #tryLock()} method simply locks a region of size {@link - * Long#MAX_VALUE}. - * - * <p> Some operating systems do not support shared locks, in which case a - * request for a shared lock is automatically converted into a request for - * an exclusive lock. Whether the newly-acquired lock is shared or - * exclusive may be tested by invoking the resulting lock object's {@link - * FileLock#isShared() isShared} method. - * - * <p> File locks are held on behalf of the entire Java virtual machine. - * They are not suitable for controlling access to a file by multiple - * threads within the same virtual machine. </p> - * - * @param position - * The position at which the locked region is to start; must be - * non-negative - * - * @param size - * The size of the locked region; must be non-negative, and the sum - * <tt>position</tt> + <tt>size</tt> must be non-negative - * - * @param shared - * <tt>true</tt> to request a shared lock, - * <tt>false</tt> to request an exclusive lock - * - * @return A lock object representing the newly-acquired lock, - * or <tt>null</tt> if the lock could not be acquired - * because another program holds an overlapping lock - * - * @throws IllegalArgumentException - * If the preconditions on the parameters do not hold - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws OverlappingFileLockException - * If a lock that overlaps the requested region is already held by - * this Java virtual machine, or if another thread is already - * blocked in this method and is attempting to lock an overlapping - * region of the same file - * - * @throws IOException - * If some other I/O error occurs - * - * @see #lock() - * @see #lock(long,long,boolean) - * @see #tryLock() - */ - public abstract FileLock tryLock(long position, long size, boolean shared) - throws IOException; - - /** - * Attempts to acquire an exclusive lock on this channel's file. - * - * <p> An invocation of this method of the form <tt>fc.tryLock()</tt> - * behaves in exactly the same way as the invocation - * - * <pre> - * fc.{@link #tryLock(long,long,boolean) tryLock}(0L, Long.MAX_VALUE, false) </pre> - * - * @return A lock object representing the newly-acquired lock, - * or <tt>null</tt> if the lock could not be acquired - * because another program holds an overlapping lock - * - * @throws ClosedChannelException - * If this channel is closed - * - * @throws OverlappingFileLockException - * If a lock that overlaps the requested region is already held by - * this Java virtual machine, or if another thread is already - * blocked in this method and is attempting to lock an overlapping - * region - * - * @throws IOException - * If some other I/O error occurs - * - * @see #lock() - * @see #lock(long,long,boolean) - * @see #tryLock(long,long,boolean) - */ - public final FileLock tryLock() throws IOException { - return tryLock(0L, Long.MAX_VALUE, false); - } }
--- a/overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/util/concurrent/ScheduledThreadPoolExecutor.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/java/util/concurrent/ScheduledThreadPoolExecutor.java Thu Jan 15 02:31:47 2009 +0000 @@ -54,6 +54,7 @@ import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; +import org.classpath.icedtea.misc.JavaUtilConcurrentThreadPoolExecutorAccess; import org.classpath.icedtea.misc.SharedSecrets; /** @@ -1285,12 +1286,15 @@ private static final int COUNT_BITS = Integer.SIZE - 3; private static final int CAPACITY = (1 << COUNT_BITS) - 1; + private static final int RUNNING = -1 << COUNT_BITS; + private static final int SHUTDOWN = 0 << COUNT_BITS; private static final int TIDYING = 2 << COUNT_BITS; - private static final int SHUTDOWN = 0 << COUNT_BITS; + private static final int TERMINATED = 3 << COUNT_BITS; // Packing and unpacking ctl private static int runStateOf(int c) { return c & ~CAPACITY; } private static int workerCountOf(int c) { return c & CAPACITY; } + private static int ctlOf(int rs, int wc) { return rs | wc; } private static final boolean ONLY_ONE = true; @@ -1312,27 +1316,26 @@ int c = ctl.get(); if (isRunning(c) || runStateAtLeast(c, TIDYING) || - (runStateOf(c) == SHUTDOWN && ! workQueue.isEmpty())) + (runStateOf(c) == SHUTDOWN && ! juctpea.isWorkQueueEmpty(this))) return; if (workerCountOf(c) != 0) { // Eligible to terminate - interruptIdleWorkers(ONLY_ONE); + juctpea.interruptIdleWorkers(this, ONLY_ONE); return; } - final ReentrantLock mainLock = juctpea.getMainLock(this); - mainLock.lock(); + juctpea.lockMainLock(this); try { if (ctl.compareAndSet(c, ctlOf(TIDYING, 0))) { try { terminated(); } finally { ctl.set(ctlOf(TERMINATED, 0)); - juctpea.getTermination(this).signalAll(); + juctpea.signalAll(this); } return; } } finally { - mainLock.unlock(); + juctpea.unlockMainLock(this); } // else retry on failed CAS } @@ -1345,7 +1348,7 @@ * @param shutdownOK true if should return true if SHUTDOWN */ private final boolean isRunningOrShutdownSTPE(boolean shutdownOK) { - int rs = runStateOf(ctl.get()); + int rs = runStateOf(SharedSecrets.getJavaUtilConcurrentThreadPoolExecutorAccess().getCtl(this).get()); return rs == RUNNING || (rs == SHUTDOWN && shutdownOK); } @@ -1354,11 +1357,15 @@ * Package-protected for use by ScheduledThreadPoolExecutor. */ private final void rejectSTPE(Runnable command) { - SharedSecrets.getJavaUtilConcurrentThreadPoolExecutorAccess().getHandler(this).rejectedExecution(command, this); + SharedSecrets.getJavaUtilConcurrentThreadPoolExecutorAccess().rejectedExecution(command, this); } private static boolean isRunning(int c) { return c < SHUTDOWN; } + private static boolean runStateAtLeast(int c, int s) { + return c >= s; + } + }
--- a/overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/misc/JavaUtilConcurrentThreadPoolExecutorAccess.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/org/classpath/icedtea/misc/JavaUtilConcurrentThreadPoolExecutorAccess.java Thu Jan 15 02:31:47 2009 +0000 @@ -48,8 +48,11 @@ public interface JavaUtilConcurrentThreadPoolExecutorAccess { AtomicInteger getCtl(ThreadPoolExecutor e); - ReentrantLock getMainLock(ThreadPoolExecutor e); - Condition getTermination(ThreadPoolExecutor e); - RejectedExecutionHandler getHandler(ThreadPoolExecutor e); + void lockMainLock(ThreadPoolExecutor e); + void unlockMainLock(ThreadPoolExecutor e); + void signalAll(ThreadPoolExecutor e); + void rejectedExecution(Runnable command, ThreadPoolExecutor e); + boolean isWorkQueueEmpty(ThreadPoolExecutor e); + void interruptIdleWorkers(ThreadPoolExecutor e, boolean onlyOne); }
--- a/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java Thu Jan 15 02:31:47 2009 +0000 @@ -29,7 +29,14 @@ import java.io.IOException; import java.io.FileDescriptor; import java.util.Queue; -import java.util.concurrent.*; + +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; + import java.util.concurrent.locks.*; import java.util.concurrent.atomic.AtomicInteger; import java.security.PrivilegedAction; @@ -40,6 +47,8 @@ import org.classpath.icedtea.java.nio.channels.AsynchronousChannelGroup; import org.classpath.icedtea.java.nio.channels.spi.AsynchronousChannelProvider; +import org.classpath.icedtea.java.util.concurrent.ScheduledThreadPoolExecutor; + /** * Base implementation of AsynchronousChannelGroup */ @@ -95,8 +104,8 @@ // use default thread factory as thread should not be visible to // application (it doesn't execute completion handlers). - this.timeoutExecutor = (ScheduledThreadPoolExecutor) - Executors.newScheduledThreadPool(1, ThreadPool.defaultThreadFactory()); + this.timeoutExecutor = + new ScheduledThreadPoolExecutor(1, ThreadPool.defaultThreadFactory()); this.timeoutExecutor.setRemoveOnCancelPolicy(true); }
--- a/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java Thu Jan 15 02:31:47 2009 +0000 @@ -25,13 +25,16 @@ package sun.nio.ch; -import java.nio.channels.*; +import java.nio.channels.AsynchronousCloseException; +import java.nio.channels.ClosedChannelException; + import java.util.concurrent.ExecutorService; import java.util.concurrent.locks.*; import java.io.FileDescriptor; import java.io.IOException; import org.classpath.icedtea.java.nio.channels.AsynchronousFileChannel; +import org.classpath.icedtea.java.nio.channels.FileLock; /** * Base implementation of AsynchronousFileChannel. @@ -120,7 +123,7 @@ try { fileLockTable.removeAll( new FileLockTable.Releaser() { public void release(FileLock fl) { - ((FileLockImpl)fl).invalidate(); + ((AsynchronousFileLockImpl)fl).invalidate(); } }); } catch (IOException e) { @@ -132,8 +135,8 @@ /** * Adds region to lock table */ - protected final FileLockImpl addToFileLockTable(long position, long size, boolean shared) { - final FileLockImpl fli; + protected final AsynchronousFileLockImpl addToFileLockTable(long position, long size, boolean shared) { + final AsynchronousFileLockImpl fli; try { // like begin() but returns null instead of exception closeLock.readLock().lock(); @@ -146,7 +149,7 @@ // should not happen throw new AssertionError(x); } - fli = new FileLockImpl(this, position, size, shared); + fli = new AsynchronousFileLockImpl(this, position, size, shared); // may throw OverlappedFileLockException fileLockTable.add(fli); } finally { @@ -155,12 +158,12 @@ return fli; } - protected final void removeFromFileLockTable(FileLockImpl fli) { + protected final void removeFromFileLockTable(AsynchronousFileLockImpl fli) { fileLockTable.remove(fli); } /** * Invoked by FileLockImpl to release lock acquired by this channel. */ - abstract void release(FileLockImpl fli) throws IOException; + abstract void release(AsynchronousFileLockImpl fli) throws IOException; }
--- a/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileLockImpl.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/AsynchronousFileLockImpl.java Thu Jan 15 02:31:47 2009 +0000 @@ -38,7 +38,7 @@ { boolean valid; - FileLockImpl(AsynchronousFileChannel channel, long position, long size, boolean shared) + AsynchronousFileLockImpl(AsynchronousFileChannel channel, long position, long size, boolean shared) { super(channel, position, size, shared); this.valid = true;
--- a/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/FileLockTable.java Wed Jan 14 05:29:15 2009 +0000 +++ b/overlays/nio2/openjdk/jdk/src/share/classes/sun/nio/ch/FileLockTable.java Thu Jan 15 02:31:47 2009 +0000 @@ -25,13 +25,17 @@ package sun.nio.ch; -import java.nio.channels.*; +import java.nio.channels.Channel; +import java.nio.channels.OverlappingFileLockException; + import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.lang.ref.*; import java.io.FileDescriptor; import java.io.IOException; +import org.classpath.icedtea.java.nio.channels.FileLock; + abstract class FileLockTable { protected FileLockTable() { }
--- a/patches/icedtea-nio2.patch Wed Jan 14 05:29:15 2009 +0000 +++ b/patches/icedtea-nio2.patch Thu Jan 15 02:31:47 2009 +0000 @@ -764,8 +764,8 @@ diff -Nru openjdk.orig/jdk/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java openjdk/jdk/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java --- openjdk.orig/jdk/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java 2009-01-13 23:54:13.000000000 +0000 -+++ openjdk/jdk/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java 2009-01-14 01:30:11.000000000 +0000 -@@ -2004,4 +2004,16 @@ ++++ openjdk/jdk/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java 2009-01-15 01:21:36.000000000 +0000 +@@ -2004,4 +2004,23 @@ } } } @@ -774,9 +774,16 @@ + org.classpath.icedtea.misc.SharedSecrets.setJavaUtilConcurrentThreadPoolExecutorAccess( + new org.classpath.icedtea.misc.JavaUtilConcurrentThreadPoolExecutorAccess() { + public AtomicInteger getCtl(ThreadPoolExecutor e) { return e.ctl; } -+ public ReentrantLock getMainLock(ThreadPoolExecutor e) { return e.mainLock; } -+ public Condition getTermination(ThreadPoolExecutor e) { return e.termination; } -+ public RejectedExecutionHandler getHandler(ThreadPoolExecutor e) { return e.handler; } ++ public void lockMainLock(ThreadPoolExecutor e) { e.mainLock.lock(); } ++ public void unlockMainLock(ThreadPoolExecutor e) { e.mainLock.unlock(); } ++ public void signalAll(ThreadPoolExecutor e) { e.termination.signalAll(); } ++ public boolean isWorkQueueEmpty(ThreadPoolExecutor e) { return e.workQueue.isEmpty(); } ++ public void rejectedExecution(Runnable command, ThreadPoolExecutor e) { ++ e.handler.rejectedExecution(command, e); ++ } ++ public void interruptIdleWorkers(ThreadPoolExecutor e, boolean onlyOne) { ++ e.interruptIdleWorkers(onlyOne); ++ } + } + ); + }