diff options
Diffstat (limited to 'libjava')
24 files changed, 587 insertions, 248 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 81ff3c8fb49..6d6bef554cd 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,54 @@ +2006-01-04 Krister Walfridsson <cato@df.lth.se> + + * posix-threads.cc (_Jv_InitThreads): #ifdef PTHREAD_STACK_MIN + +2006-01-04 Tom Tromey <tromey@redhat.com> + + * java/lang/Class.h (_Jv_CopyClassesToSystemLoader): Updated. + * java/lang/natClassLoader.cc (_Jv_CopyClassesToSystemLoader): + Changed argument type. Use SystemClassLoader.addClass. + * gnu/gcj/runtime/SystemClassLoader.java (addClass): New method. + +2005-12-24 David Daney <ddaney@avtrex.com> + Tom Tromey <tromey@redhat.com> + + PR libgcj/9715, PR libgcj/19132: + * java/nio/charset/Charset.java (charsetForName): Try default + provider first. + (availableCharsets): Re-merged. + (providers2): Likewise. + (defaultCharset): Likewise. + * sources.am, Makefile.in: Rebuilt. + * gnu/java/nio/charset/Provider.java: Removed. + * java/io/OutputStreamWriter.java + (OutputStreamWriter(OutputStream,Charset)): New constructor. + (OutputStreamWriter(OutputStream,CharsetEncoder)): Likewise. + * java/io/InputStreamReader.java + (InputStreamReader(InputStream,CharsetDecoder)): New constructor. + (InputStreamReader(InputStream,Charset)): Likewise. + * gnu/gcj/convert/BytesToUnicode.java (getDecoder): Try a + BytesToCharsetAdaptor. + * gnu/gcj/convert/UnicodeToBytes.java (getEncoder): Try a + CharsetToBytesAdaptor. + * gnu/gcj/convert/CharsetToBytesAdaptor.java: New file. + * gnu/gcj/convert/BytesToCharsetAdaptor.java: New file. + * mauve-libgcj: Remove getEncoding exclusion. + +2005-12-28 Anthony Green <green@redhat.com> + + * gnu/java/net/natPlainSocketImplWin32.cc (connect): Same + as previous patch, but for win32. + +2005-12-28 Anthony Green <green@redhat.com> + + * gnu/java/net/natPlainSocketImplPosix.cc (connect): Record + address and port before attempting anything. + +2005-12-28 John David Anglin <dave.anglin@nrc-cnrc.gc.ca> + + * sysdep/pa/locks.h (compare_and_swap): Add ldcw semaphore to make + operation atomic. + 2005-12-22 Tom Tromey <tromey@redhat.com> * java/lang/natClassLoader.cc (_Jv_NewArrayClass): Don't diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 1223452a6dd..16f6aeab537 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -1138,7 +1138,9 @@ gnu/gcj/RawDataManaged.java gnu_gcj_header_files = $(patsubst %.java,%.h,$(gnu_gcj_source_files)) gnu_gcj_convert_source_files = \ +gnu/gcj/convert/BytesToCharsetAdaptor.java \ gnu/gcj/convert/BytesToUnicode.java \ +gnu/gcj/convert/CharsetToBytesAdaptor.java \ gnu/gcj/convert/Convert.java \ gnu/gcj/convert/IOConverter.java \ gnu/gcj/convert/Input_8859_1.java \ @@ -1712,7 +1714,7 @@ classpath/gnu/java/nio/charset/MacRomania.java \ classpath/gnu/java/nio/charset/MacSymbol.java \ classpath/gnu/java/nio/charset/MacThai.java \ classpath/gnu/java/nio/charset/MacTurkish.java \ -gnu/java/nio/charset/Provider.java \ +classpath/gnu/java/nio/charset/Provider.java \ classpath/gnu/java/nio/charset/US_ASCII.java \ classpath/gnu/java/nio/charset/UTF_16.java \ classpath/gnu/java/nio/charset/UTF_16BE.java \ diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog index 125388f5d6f..85df787cc4d 100644 --- a/libjava/classpath/ChangeLog +++ b/libjava/classpath/ChangeLog @@ -1,3 +1,19 @@ +2005-12-27 Tom Tromey <tromey@redhat.com> + + * gnu/java/nio/SelectorImpl.java: Added import. + +2005-12-26 Anthony Green <green@redhat.com> + + * java/net/Socket.java (connect): Don't close the socket on + exceptions. + + * gnu/java/nio/SocketChannelImpl.java (read): Compute the right amount + of data to read (dst.remaining()). + * gnu/java/nio/DatagramChannelImpl.java (receive): Ditto. + + * gnu/java/nio/SelectorImpl.java (select): Handle OP_CONNECT + properly. + 2005-11-17 Roman Kennke <kennke@aicas.com> * javax/swing/JEditorPane.java diff --git a/libjava/classpath/gnu/java/nio/DatagramChannelImpl.java b/libjava/classpath/gnu/java/nio/DatagramChannelImpl.java index 51c7031fe69..4687bf3f59e 100644 --- a/libjava/classpath/gnu/java/nio/DatagramChannelImpl.java +++ b/libjava/classpath/gnu/java/nio/DatagramChannelImpl.java @@ -201,7 +201,7 @@ public final class DatagramChannelImpl extends DatagramChannel try { DatagramPacket packet; - int len = dst.capacity() - dst.position(); + int len = dst.remaining(); if (dst.hasArray()) { diff --git a/libjava/classpath/gnu/java/nio/SelectorImpl.java b/libjava/classpath/gnu/java/nio/SelectorImpl.java index dcafedeb8bb..e10f7157443 100644 --- a/libjava/classpath/gnu/java/nio/SelectorImpl.java +++ b/libjava/classpath/gnu/java/nio/SelectorImpl.java @@ -43,6 +43,7 @@ import java.nio.channels.ClosedSelectorException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; import java.nio.channels.spi.AbstractSelectableChannel; import java.nio.channels.spi.AbstractSelector; import java.nio.channels.spi.SelectorProvider; @@ -284,19 +285,18 @@ public class SelectorImpl extends AbstractSelector // Set new ready write ops for (int i = 0; i < write.length; i++) { - if (key.getNativeFD() == write[i]) - { - ops = ops | SelectionKey.OP_WRITE; - - // if (key.channel ().isConnected ()) - // { - // ops = ops | SelectionKey.OP_WRITE; - // } - // else - // { - // ops = ops | SelectionKey.OP_CONNECT; - // } - } + if (key.getNativeFD() == write[i]) + { + if (key.channel() instanceof SocketChannel) + { + if (((SocketChannel) key.channel ()).isConnected ()) + ops = ops | SelectionKey.OP_WRITE; + else + ops = ops | SelectionKey.OP_CONNECT; + } + else + ops = ops | SelectionKey.OP_WRITE; + } } // FIXME: We dont handle exceptional file descriptors yet. diff --git a/libjava/classpath/gnu/java/nio/SocketChannelImpl.java b/libjava/classpath/gnu/java/nio/SocketChannelImpl.java index fcddbd6c351..680eba2f92b 100644 --- a/libjava/classpath/gnu/java/nio/SocketChannelImpl.java +++ b/libjava/classpath/gnu/java/nio/SocketChannelImpl.java @@ -220,7 +220,7 @@ public final class SocketChannelImpl extends SocketChannel int offset = 0; InputStream input = socket.getInputStream(); int available = input.available(); - int len = dst.capacity() - dst.position(); + int len = dst.remaining(); if ((! isBlocking()) && available == 0) return 0; diff --git a/libjava/classpath/java/net/Socket.java b/libjava/classpath/java/net/Socket.java index 0ff6e6ea032..b2249ffaa0d 100644 --- a/libjava/classpath/java/net/Socket.java +++ b/libjava/classpath/java/net/Socket.java @@ -437,25 +437,7 @@ public class Socket if (! isBound()) bind(null); - try - { - getImpl().connect(endpoint, timeout); - } - catch (IOException exception) - { - close(); - throw exception; - } - catch (RuntimeException exception) - { - close(); - throw exception; - } - catch (Error error) - { - close(); - throw error; - } + getImpl().connect(endpoint, timeout); } /** diff --git a/libjava/gnu/gcj/convert/BytesToCharsetAdaptor.java b/libjava/gnu/gcj/convert/BytesToCharsetAdaptor.java new file mode 100644 index 00000000000..78ba848e118 --- /dev/null +++ b/libjava/gnu/gcj/convert/BytesToCharsetAdaptor.java @@ -0,0 +1,90 @@ +/* Copyright (C) 2005 Free Software Foundation + +This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.convert; + +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; +import java.nio.charset.CoderResult; +import gnu.java.nio.charset.EncodingHelper; + +/** + * Adaptor class that allow any {@link Charset} to be used + * as a BytesToUnicode converter. + */ +public class BytesToCharsetAdaptor extends BytesToUnicode +{ + /** + * The CharsetDecoder that does all the work. + */ + private final CharsetDecoder decoder; + + /** + * ByteBuffer wrapper for this.buf. + */ + private ByteBuffer inBuf; + + /** + * Create a new BytesToCharsetAdaptor for the given Charset. + * + * @param cs the Charset. + */ + public BytesToCharsetAdaptor(Charset cs) + { + this(cs.newDecoder()); + } + + /** + * Create a new BytesToCharsetAdaptor for the given CharsetDecoder. + * + * @param dec the CharsetDecoder. + */ + public BytesToCharsetAdaptor(CharsetDecoder dec) + { + decoder = dec; + // Use default replacments on bad input so that we don't have to + // deal with errors. + decoder.onMalformedInput(CodingErrorAction.REPLACE); + decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); + } + + /** + * Return the decoder's name. The backing Charset's name is + * returned. + * + * @return The name. + */ + public String getName() + { + return EncodingHelper.getOldCanonical(decoder.charset().name()); + } + + public int read(char[] outbuffer, int outpos, int count) + { + if (inBuf == null || ! inBuf.hasArray() || inBuf.array() != inbuffer) + inBuf = ByteBuffer.wrap(inbuffer); + inBuf.limit(inpos + inlength); + inBuf.position(inpos); + + CharBuffer outBuf = CharBuffer.wrap(outbuffer, outpos, count); + decoder.decode(inBuf, outBuf, false); + + // Update this.inpos to reflect the bytes consumed. + inpos = inBuf.position(); + // Return the number of characters that were written to outbuffer. + return outBuf.position() - outpos; + } + + // These aren't cached. + public void done() + { + } +} diff --git a/libjava/gnu/gcj/convert/BytesToUnicode.java b/libjava/gnu/gcj/convert/BytesToUnicode.java index f33720aa227..e3afe3ee97b 100644 --- a/libjava/gnu/gcj/convert/BytesToUnicode.java +++ b/libjava/gnu/gcj/convert/BytesToUnicode.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2000, 2001 Free Software Foundation +/* Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation This file is part of libgcj. @@ -8,6 +8,8 @@ details. */ package gnu.gcj.convert; +import java.nio.charset.Charset; + public abstract class BytesToUnicode extends IOConverter { /** Buffer to read bytes from. @@ -104,11 +106,20 @@ public abstract class BytesToUnicode extends IOConverter try { // We pass the original name to iconv and let it handle - // its own aliasing. + // its own aliasing. Note that we intentionally prefer + // iconv over nio. return new Input_iconv (encoding); } catch (Throwable _) { + // Ignore, and try the next method. + } + try + { + return new BytesToCharsetAdaptor(Charset.forName(encoding)); + } + catch (Throwable _) + { throw new java.io.UnsupportedEncodingException(encoding + " (" + ex + ')'); } diff --git a/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java b/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java new file mode 100644 index 00000000000..4e9bcd5b461 --- /dev/null +++ b/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java @@ -0,0 +1,150 @@ +/* Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.convert; + +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; +import java.nio.charset.CodingErrorAction; +import java.nio.charset.CoderResult; +import gnu.java.nio.charset.EncodingHelper; + +/** + * Adaptor class that allow any {@link Charset} to be used + * as a UnicodeToBytes converter. + */ +public class CharsetToBytesAdaptor extends UnicodeToBytes +{ + /** + * The CharsetEncoder that does all the work. + */ + private final CharsetEncoder encoder; + + /** + * ByteBuffer wrapper for this.buf. + */ + private ByteBuffer outBuf; + + /** + * True if we've told the CharsetEncoder that there are no more + * characters available. + */ + private boolean closedEncoder; + + /** + * True if we're finished. + */ + private boolean finished; + + /** + * Create a new CharsetToBytesAdaptor for the given Charset. + * + * @param cs The Charset. + */ + public CharsetToBytesAdaptor(Charset cs) + { + this(cs.newEncoder()); + } + + /** + * Create a new CharsetToBytesAdaptor for the given CharsetEncoder. + * + * @param enc The CharsetEncoder. + */ + public CharsetToBytesAdaptor(CharsetEncoder enc) + { + encoder = enc; + // Use default replacments on bad input so that we don't have to + // deal with errors. + encoder.onMalformedInput(CodingErrorAction.REPLACE); + encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); + } + + /** + * Return the encoder's name. The backing Charset's name is + * returned. + * + * @return The name. + */ + public String getName() + { + return EncodingHelper.getOldCanonical(encoder.charset().name()); + } + + public int write (char[] inbuffer, int inpos, int inlength) + { + // Wrap the char array so it can be used by the encoder. + CharBuffer b = CharBuffer.wrap(inbuffer, inpos, inlength); + write(b); + return b.position() - inpos; // Number of chars consumed. + } + + public int write (String str, int inpos, int inlength, char work) + { + // Wrap the String so it can be used by the encoder. + CharBuffer b = CharBuffer.wrap(str, inpos, inlength); + write(b); + return b.position() - inpos; // Number of chars consumed. + } + + /** + * Encode as much of inBuf as will fit in buf. The number of + * chars consumed is reflected by the new position of inBuf. The + * output is put in buf and count is incremented by the number of + * bytes written. + * + * @param inBuf The input. + */ + private void write(CharBuffer inBuf) + { + // Reuse existing outBuf if it is still wrapping the same array + // it was created with. + if (outBuf == null || !outBuf.hasArray() || outBuf.array() != buf) + outBuf = ByteBuffer.wrap(buf); + + // Set the current position. + outBuf.position(count); + + // If we've already said that there is no more input available, + // then we simply try to flush again. + if (closedEncoder) + { + CoderResult result = encoder.flush(outBuf); + if (result == CoderResult.UNDERFLOW) + finished = true; + } + else + { + // Do the conversion. If there are no characters to write, + // then we are finished. + closedEncoder = ! inBuf.hasRemaining(); + encoder.encode(inBuf, outBuf, closedEncoder); + } + + // Mark the new end of buf. + count = outBuf.position(); + } + + /** + * Check for cached output in the converter. + * + * @return true if there is cached output that has not been + * written to buf. + */ + public boolean havePendingBytes() + { + return ! finished; + } + + // These aren't cached. + public void done() + { + } +} diff --git a/libjava/gnu/gcj/convert/UnicodeToBytes.java b/libjava/gnu/gcj/convert/UnicodeToBytes.java index b1432586ce5..8522bec117a 100644 --- a/libjava/gnu/gcj/convert/UnicodeToBytes.java +++ b/libjava/gnu/gcj/convert/UnicodeToBytes.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation +/* Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation This file is part of libgcj. @@ -8,6 +8,8 @@ details. */ package gnu.gcj.convert; +import java.nio.charset.Charset; + public abstract class UnicodeToBytes extends IOConverter { /** Buffer to emit bytes to. @@ -99,10 +101,22 @@ public abstract class UnicodeToBytes extends IOConverter catch (Throwable ex) { try - { + { // We pass the original name to iconv and let it handle - // its own aliasing. + // its own aliasing. Note that we intentionally prefer + // iconv over nio. return new Output_iconv (encoding); + } + catch (Throwable _) + { + // Ignore, and try the next method. + } + try + { + // Try using finding java.nio.charset.Charset and using + // the adaptor. Use the original name as Charsets have + // their own canonical names. + return new CharsetToBytesAdaptor(Charset.forName(encoding)); } catch (Throwable _) { diff --git a/libjava/gnu/gcj/runtime/SystemClassLoader.java b/libjava/gnu/gcj/runtime/SystemClassLoader.java index 1bb5ef94212..efd33230fbe 100644 --- a/libjava/gnu/gcj/runtime/SystemClassLoader.java +++ b/libjava/gnu/gcj/runtime/SystemClassLoader.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 Free Software Foundation +/* Copyright (C) 2005, 2006 Free Software Foundation This file is part of libgcj. @@ -21,6 +21,25 @@ public final class SystemClassLoader extends URLClassLoader super(new URL[0], parent); } + // This is called to register a native class which was linked into + // the application but which is registered with the system class + // loader after the VM is initialized. + void addClass(Class klass) + { + String packageName = null; + String className = klass.getName(); + int lastDot = className.lastIndexOf('.'); + if (lastDot != -1) + packageName = className.substring(0, lastDot); + if (packageName != null && getPackage(packageName) == null) + { + // Should have some way to store this information in a + // precompiled manifest. + definePackage(packageName, null, null, null, null, null, null, null); + } + loadedClasses.put(className, klass); + } + // We add the URLs to the system class loader late. The reason for // this is that during bootstrap we don't want to parse URLs or // create URL connections, since that will result in circularities diff --git a/libjava/gnu/java/net/natPlainSocketImplPosix.cc b/libjava/gnu/java/net/natPlainSocketImplPosix.cc index 643f4e4909a..be9437cd7db 100644 --- a/libjava/gnu/java/net/natPlainSocketImplPosix.cc +++ b/libjava/gnu/java/net/natPlainSocketImplPosix.cc @@ -142,6 +142,15 @@ gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr, ::java::net::InetAddress *host = tmp->getAddress(); jint rport = tmp->getPort(); + // Set the SocketImpl's address and port fields before we try to + // connect. Note that the fact that these are set doesn't imply + // that we're actually connected to anything. We need to record + // this data before we attempt the connect, since non-blocking + // SocketChannels will use this and almost certainly throw timeout + // exceptions. + address = host; + port = rport; + union SockAddr u; socklen_t addrlen = sizeof(u); jbyteArray haddress = host->addr; @@ -197,9 +206,6 @@ gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr, goto error; } - address = host; - port = rport; - // A bind may not have been done on this socket; if so, set localport now. if (localport == 0) { diff --git a/libjava/gnu/java/net/natPlainSocketImplWin32.cc b/libjava/gnu/java/net/natPlainSocketImplWin32.cc index 48c7171c7c1..f54edb54630 100644 --- a/libjava/gnu/java/net/natPlainSocketImplWin32.cc +++ b/libjava/gnu/java/net/natPlainSocketImplWin32.cc @@ -133,6 +133,15 @@ gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr, ::java::net::InetAddress *host = tmp->getAddress(); jint rport = tmp->getPort(); + // Set the SocketImpl's address and port fields before we try to + // connect. Note that the fact that these are set doesn't imply + // that we're actually connected to anything. We need to record + // this data before we attempt the connect, since non-blocking + // SocketChannels will use this and almost certainly throw timeout + // exceptions. + address = host; + port = rport; + union SockAddr u; socklen_t addrlen = sizeof(u); jbyteArray haddress = host->addr; @@ -208,9 +217,6 @@ gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr, throwConnectException(); } - address = host; - port = rport; - // A bind may not have been done on this socket; if so, set localport now. if (localport == 0) { diff --git a/libjava/gnu/java/nio/charset/Provider.java b/libjava/gnu/java/nio/charset/Provider.java deleted file mode 100644 index 586a09e1a1b..00000000000 --- a/libjava/gnu/java/nio/charset/Provider.java +++ /dev/null @@ -1,154 +0,0 @@ -/* Provider.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio.charset; - -import java.nio.charset.Charset; -import java.nio.charset.spi.CharsetProvider; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; - -/** - * Charset provider for the required charsets. Used by - * {@link Charset#charsetForName} and * {@link Charset#availableCharsets}. - * - * @author Jesse Rosenstock - * @author Robert Schuster (thebohemian@gmx.net) - * @see Charset - */ -public final class Provider extends CharsetProvider -{ - private static Provider singleton; - - static - { - synchronized (Provider.class) - { - singleton = null; - } - } - - /** - * Map from charset name to charset canonical name. The strings - * are all lower-case to allow case-insensitive retrieval of - * Charset instances. - */ - private final HashMap canonicalNames; - - /** - * Map from lower-case canonical name to Charset. - * TODO: We may want to use soft references. We would then need to keep - * track of the class name to regenerate the object. - */ - private final HashMap charsets; - - private Provider () - { - canonicalNames = new HashMap (); - charsets = new HashMap (); - - // US-ASCII aka ISO646-US - addCharset (new US_ASCII ()); - - // ISO-8859-1 aka ISO-LATIN-1 - addCharset (new ISO_8859_1 ()); - - // UTF-8 - addCharset (new UTF_8 ()); - - // UTF-16BE - addCharset (new UTF_16BE ()); - - // UTF-16LE - addCharset (new UTF_16LE ()); - - // UTF-16 - addCharset (new UTF_16 ()); - } - - public Iterator charsets () - { - return Collections.unmodifiableCollection (charsets.values ()) - .iterator (); - } - - /** - * Returns a Charset instance by converting the given - * name to lower-case, looking up the canonical charset - * name and finally looking up the Charset with that name. - * - * <p>The lookup is therefore case-insensitive.</p> - * - * @returns The Charset having <code>charsetName</code> - * as its alias or null if no such Charset exist. - */ - public Charset charsetForName (String charsetName) - { - return (Charset) charsets.get(canonicalNames.get(charsetName.toLowerCase())); - } - - /** - * Puts a Charset under its canonical name into the 'charsets' map. - * Then puts a mapping from all its alias names to the canonical name. - * - * <p>All names are converted to lower-case</p>. - * - * @param cs - */ - private void addCharset (Charset cs) - { - String canonicalName = cs.name().toLowerCase(); - charsets.put (canonicalName, cs); - - /* Adds a mapping between the canonical name - * itself making a lookup using that name - * no special case. - */ - canonicalNames.put(canonicalName, canonicalName); - - for (Iterator i = cs.aliases ().iterator (); i.hasNext (); ) - canonicalNames.put (((String) i.next()).toLowerCase(), canonicalName); - } - - public static synchronized Provider provider () - { - if (singleton == null) - singleton = new Provider (); - return singleton; - } -} diff --git a/libjava/java/io/InputStreamReader.java b/libjava/java/io/InputStreamReader.java index e55f1352caa..91568c5cc50 100644 --- a/libjava/java/io/InputStreamReader.java +++ b/libjava/java/io/InputStreamReader.java @@ -39,6 +39,8 @@ exception statement from your version. */ package java.io; import gnu.gcj.convert.*; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; /** * This class reads characters from a byte input stream. The characters @@ -131,6 +133,25 @@ public class InputStreamReader extends Reader this(in, BytesToUnicode.getDecoder(encoding_name)); } + /** + * Creates an InputStreamReader that uses a decoder of the given + * charset to decode the bytes in the InputStream into + * characters. + */ + public InputStreamReader(InputStream in, Charset charset) + { + this(in, new BytesToCharsetAdaptor(charset)); + } + + /** + * Creates an InputStreamReader that uses the given charset decoder + * to decode the bytes in the InputStream into characters. + */ + public InputStreamReader(InputStream in, CharsetDecoder decoder) + { + this(in, new BytesToCharsetAdaptor(decoder)); + } + private InputStreamReader(InputStream in, BytesToUnicode decoder) { // FIXME: someone could pass in a BufferedInputStream whose buffer diff --git a/libjava/java/io/OutputStreamWriter.java b/libjava/java/io/OutputStreamWriter.java index 8b7beeb497b..90ecd9f0bc3 100644 --- a/libjava/java/io/OutputStreamWriter.java +++ b/libjava/java/io/OutputStreamWriter.java @@ -39,6 +39,9 @@ exception statement from your version. */ package java.io; import gnu.gcj.convert.UnicodeToBytes; +import gnu.gcj.convert.CharsetToBytesAdaptor; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; /** * This class writes characters to an output stream that is byte oriented @@ -129,6 +132,31 @@ public class OutputStreamWriter extends Writer } /** + * This method initializes a new instance of <code>OutputStreamWriter</code> + * to write to the specified stream using a given <code>Charset</code>. + * + * @param out The <code>OutputStream</code> to write to + * @param cs The <code>Charset</code> of the encoding to use + */ + public OutputStreamWriter(OutputStream out, Charset cs) + { + this(out, new CharsetToBytesAdaptor(cs)); + } + + /** + * This method initializes a new instance of <code>OutputStreamWriter</code> + * to write to the specified stream using a given + * <code>CharsetEncoder</code>. + * + * @param out The <code>OutputStream</code> to write to + * @param enc The <code>CharsetEncoder</code> to encode the output with + */ + public OutputStreamWriter(OutputStream out, CharsetEncoder enc) + { + this(out, new CharsetToBytesAdaptor(enc)); + } + + /** * This method closes this stream, and the underlying * <code>OutputStream</code> * diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h index a2ec357f770..1c14df3a9c3 100644 --- a/libjava/java/lang/Class.h +++ b/libjava/java/lang/Class.h @@ -1,6 +1,6 @@ // Class.h - Header file for java.lang.Class. -*- c++ -*- -/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation This file is part of libgcj. @@ -22,6 +22,21 @@ details. */ #include <java/security/ProtectionDomain.h> #include <java/lang/Package.h> +// Avoid including SystemClassLoader.h. +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace runtime + { + class SystemClassLoader; + } + } + } +} + // We declare these here to avoid including gcj/cni.h. extern "C" void _Jv_InitClass (jclass klass); extern "C" void _Jv_RegisterClasses (const jclass *classes); @@ -237,7 +252,7 @@ jclass _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader); jboolean _Jv_IsInterpretedClass (jclass); jboolean _Jv_IsBinaryCompatibilityABI (jclass); -void _Jv_CopyClassesToSystemLoader (java::lang::ClassLoader *); +void _Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::SystemClassLoader *); #ifdef INTERPRETER void _Jv_InitField (jobject, jclass, int); @@ -498,7 +513,7 @@ private: friend void *::_Jv_ResolvePoolEntry (jclass this_class, jint index); - friend void ::_Jv_CopyClassesToSystemLoader (java::lang::ClassLoader *); + friend void ::_Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::SystemClassLoader *); // Chain for class pool. This also doubles as the ABI version // number. It is only used for this purpose at class registration diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc index cfb061291a7..797005b54c7 100644 --- a/libjava/java/lang/natClassLoader.cc +++ b/libjava/java/lang/natClassLoader.cc @@ -1,6 +1,6 @@ // natClassLoader.cc - Implementation of java.lang.ClassLoader native methods. -/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation +/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation This file is part of libgcj. @@ -43,6 +43,7 @@ details. */ #include <java/lang/Cloneable.h> #include <java/util/HashMap.h> #include <gnu/gcj/runtime/BootClassLoader.h> +#include <gnu/gcj/runtime/SystemClassLoader.h> // Size of local hash table. #define HASH_LEN 1013 @@ -253,14 +254,14 @@ _Jv_RegisterClass (jclass klass) // This is used during initialization to register all compiled-in // classes that are not part of the core with the system class loader. void -_Jv_CopyClassesToSystemLoader (java::lang::ClassLoader *loader) +_Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::SystemClassLoader *loader) { for (jclass klass = system_class_list; klass; klass = klass->next_or_version) { klass->loader = loader; - loader->loadedClasses->put(klass->name->toString(), klass); + loader->addClass(klass); } system_class_list = SYSTEM_LOADER_INITIALIZED; } diff --git a/libjava/java/nio/charset/Charset.java b/libjava/java/nio/charset/Charset.java index 14b6db83b0f..48093bc9d3d 100644 --- a/libjava/java/nio/charset/Charset.java +++ b/libjava/java/nio/charset/Charset.java @@ -38,6 +38,8 @@ exception statement from your version. */ package java.nio.charset; +import gnu.classpath.ServiceFactory; +import gnu.classpath.SystemProperties; import gnu.java.nio.charset.Provider; import java.io.BufferedReader; @@ -116,6 +118,53 @@ public abstract class Charset implements Comparable } } + /** + * Returns the system default charset. + * + * This may be set by the user or VM with the file.encoding + * property. + * + * @since 1.5 + */ + public static Charset defaultCharset() + { + String encoding; + + try + { + encoding = SystemProperties.getProperty("file.encoding"); + } + catch(SecurityException e) + { + // Use fallback. + encoding = "ISO-8859-1"; + } + catch(IllegalArgumentException e) + { + // Use fallback. + encoding = "ISO-8859-1"; + } + + try + { + return forName(encoding); + } + catch(UnsupportedCharsetException e) + { + // Ignore. + } + catch(IllegalCharsetNameException e) + { + // Ignore. + } + catch(IllegalArgumentException e) + { + // Ignore. + } + + throw new IllegalStateException("Can't get default charset!"); + } + public static boolean isSupported (String charsetName) { return charsetForName (charsetName) != null; @@ -155,13 +204,19 @@ public abstract class Charset implements Comparable private static Charset charsetForName(String charsetName) { checkName (charsetName); - Charset cs = null; - CharsetProvider[] providers = providers2(); - for (int i = 0; i < providers.length; i++) + // Try the default provider first + // (so we don't need to load external providers unless really necessary) + // if it is an exotic charset try loading the external providers. + Charset cs = provider().charsetForName(charsetName); + if (cs == null) { - cs = providers[i].charsetForName(charsetName); - if (cs != null) - break; + CharsetProvider[] providers = providers2(); + for (int i = 0; i < providers.length; i++) + { + cs = providers[i].charsetForName(charsetName); + if (cs != null) + break; + } } return cs; } @@ -169,6 +224,11 @@ public abstract class Charset implements Comparable public static SortedMap availableCharsets() { TreeMap charsets = new TreeMap(String.CASE_INSENSITIVE_ORDER); + for (Iterator i = provider().charsets(); i.hasNext(); ) + { + Charset cs = (Charset) i.next(); + charsets.put(cs.name(), cs); + } CharsetProvider[] providers = providers2(); for (int j = 0; j < providers.length; j++) @@ -206,7 +266,7 @@ public abstract class Charset implements Comparable /** * We need to support multiple providers, reading them from * java.nio.charset.spi.CharsetProvider in the resource directory - * META-INF/services. + * META-INF/services. This returns the "extra" charset providers. */ private static CharsetProvider[] providers2() { @@ -214,24 +274,10 @@ public abstract class Charset implements Comparable { try { - Enumeration en = ClassLoader.getSystemResources - ("META-INF/services/java.nio.charset.spi.CharsetProvider"); + Iterator i = ServiceFactory.lookupProviders(CharsetProvider.class); LinkedHashSet set = new LinkedHashSet(); - set.add(provider()); - while (en.hasMoreElements()) - { - BufferedReader rdr = new BufferedReader(new InputStreamReader - (((URL) (en.nextElement())).openStream())); - while (true) - { - String s = rdr.readLine(); - if (s == null) - break; - CharsetProvider p = - (CharsetProvider) ((Class.forName(s)).newInstance()); - set.add(p); - } - } + while (i.hasNext()) + set.add(i.next()); providers = new CharsetProvider[set.size()]; set.toArray(providers); diff --git a/libjava/mauve-libgcj b/libjava/mauve-libgcj index 76c18f2d92b..4d4cf5bc16a 100644 --- a/libjava/mauve-libgcj +++ b/libjava/mauve-libgcj @@ -23,4 +23,3 @@ JDBC2.0 !java.awt.event.MouseEvent.modifiersEx !org.omg. !javax.rmi -!java.io.InputStreamReader.getEncoding diff --git a/libjava/posix-threads.cc b/libjava/posix-threads.cc index 042370fc379..6ef50bda8e4 100644 --- a/libjava/posix-threads.cc +++ b/libjava/posix-threads.cc @@ -338,8 +338,10 @@ _Jv_InitThreads (void) // Bigger default on 64-bit systems. min_ss *= 2; +#ifdef PTHREAD_STACK_MIN if (min_ss < PTHREAD_STACK_MIN) min_ss = PTHREAD_STACK_MIN; +#endif if (gcj::stack_size > 0 && gcj::stack_size < min_ss) gcj::stack_size = min_ss; diff --git a/libjava/sources.am b/libjava/sources.am index 4cd7e49d8fe..d976154598b 100644 --- a/libjava/sources.am +++ b/libjava/sources.am @@ -497,7 +497,9 @@ gnu/gcj.list: $(gnu_gcj_source_files) gnu_gcj_convert_source_files = \ +gnu/gcj/convert/BytesToCharsetAdaptor.java \ gnu/gcj/convert/BytesToUnicode.java \ +gnu/gcj/convert/CharsetToBytesAdaptor.java \ gnu/gcj/convert/Convert.java \ gnu/gcj/convert/IOConverter.java \ gnu/gcj/convert/Input_8859_1.java \ @@ -1350,7 +1352,7 @@ classpath/gnu/java/nio/charset/MacRomania.java \ classpath/gnu/java/nio/charset/MacSymbol.java \ classpath/gnu/java/nio/charset/MacThai.java \ classpath/gnu/java/nio/charset/MacTurkish.java \ -gnu/java/nio/charset/Provider.java \ +classpath/gnu/java/nio/charset/Provider.java \ classpath/gnu/java/nio/charset/US_ASCII.java \ classpath/gnu/java/nio/charset/UTF_16.java \ classpath/gnu/java/nio/charset/UTF_16BE.java \ diff --git a/libjava/sysdep/pa/locks.h b/libjava/sysdep/pa/locks.h index 3f24afc5669..4edc2d71626 100644 --- a/libjava/sysdep/pa/locks.h +++ b/libjava/sysdep/pa/locks.h @@ -1,6 +1,6 @@ -// locks.h - Thread synchronization primitives. PARISC implementation. +// locks.h - Thread synchronization primitives. PA-RISC implementation. -/* Copyright (C) 2002 Free Software Foundation +/* Copyright (C) 2002, 2005 Free Software Foundation This file is part of libgcj. @@ -11,30 +11,62 @@ details. */ #ifndef __SYSDEP_LOCKS_H__ #define __SYSDEP_LOCKS_H__ -typedef size_t obj_addr_t; /* Integer type big enough for object */ - /* address. */ +// Integer type big enough for object address. +typedef size_t obj_addr_t; -// Atomically replace *addr by new_val if it was initially equal to old. -// Return true if the comparison succeeded. +template<int _Inst> + struct _pa_jv_cas_lock + { + static volatile int _S_pa_jv_cas_lock; + }; + +template<int _Inst> +volatile int +_pa_jv_cas_lock<_Inst>::_S_pa_jv_cas_lock __attribute__ ((aligned (16))) = 1; + +// Because of the lack of weak support when using the hpux som +// linker, we explicitly instantiate the atomicity lock. +template volatile int _pa_jv_cas_lock<0>::_S_pa_jv_cas_lock; + +// Atomically replace *addr by new_val if it was initially equal to old_val. +// Return true if the comparison is successful. // Assumed to have acquire semantics, i.e. later memory operations // cannot execute before the compare_and_swap finishes. +// The following implementation is atomic but it can deadlock +// (e.g., if a thread dies holding the lock). inline static bool +__attribute__ ((__unused__)) compare_and_swap(volatile obj_addr_t *addr, - obj_addr_t old, + obj_addr_t old_val, obj_addr_t new_val) { - /* FIXME: not atomic */ - obj_addr_t prev; + bool result; + int tmp; + volatile int& lock = _pa_jv_cas_lock<0>::_S_pa_jv_cas_lock; - if ((prev = *addr) == old) - { - *addr = new_val; - return true; - } + __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" + "cmpib,<>,n 0,%0,.+20\n\t" + "ldw 0(%1),%0\n\t" + "cmpib,= 0,%0,.-4\n\t" + "nop\n\t" + "b,n .-20" + : "=&r" (tmp) + : "r" (&lock) + : "memory"); + + if (*addr != old_val) + result = false; else { - return false; + *addr = new_val; + result = true; } + + /* Reset lock with PA 2.0 "ordered" store. */ + __asm__ __volatile__ ("stw,ma %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); + + return result; } // Set *addr to new_val with release semantics, i.e. making sure |