diff options
author | Matthias Klose <doko@gcc.gnu.org> | 2007-06-03 23:18:43 +0000 |
---|---|---|
committer | Matthias Klose <doko@gcc.gnu.org> | 2007-06-03 23:18:43 +0000 |
commit | e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc (patch) | |
tree | a9c9e7d91c484d53fe154f9285fc57325572ce50 /libjava/classpath/vm/reference | |
parent | af333b9a7f9e1cc1029bec56d48f2de63acdf686 (diff) | |
download | gcc-e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc.zip gcc-e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc.tar.gz gcc-e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc.tar.bz2 |
libjava/classpath/ChangeLog.gcj:
2007-05-31 Matthias Klose <doko@ubuntu.com>
* javax/management/NotificationBroadcasterSupport.java
(getNotificationInfo): Add cast.
* native/jni/qt-peer/Makefile.am (AM_CXXFLAGS): Add libstdc++ include
directories.
* native/jni/qt-peer/Makefile.in: Regenerate.
libjava/ChangeLog:
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/natFileWin32.cc (setFilePermissions): New (stub only).
_access: Handle EXEC query, stub only.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Merged from classpath:
* gnu/java/nio/SelectorProviderImpl.java: Whitespace merge.
* java/lang/System.java(inheritedChannel): New.
* java/lang/Character.java: Remove stray`;'.
* java/net/MulticastSocket.java: Merged.
* java/text/DateFormatSymbols.java(getInstance): New, comment updates.
* java/text/Collator.java(getInstance): Merged.
* java/util/Calendar.java: New attributes ALL_STYLES, SHORT, LONG.
getDisplayName, getDisplayNames: New.
* java/util/logging/Logger.java: Merged.
* Regenerate .class and .h files.
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/File.java: Merge with classpath-0.95, new method
setFilePermissions, new attribute EXEC.
* java/io/natFilePosix.cc (setFilePermissions): New.
_access: Handle EXEC query.
* classpath/lib/java/io/File.class, java/io/File.h: Regenerate.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Imported GNU Classpath 0.95.
* classpath/Makefile.in,
classpath/native/jni/midi-dssi/Makefile.in,
classpath/native/jni/classpath/Makefile.in,
classpath/native/jni/Makefile.in,
classpath/native/jni/gconf-peer/Makefile.in,
classpath/native/jni/java-io/Makefile.in,
classpath/native/jni/native-lib/Makefile.in,
classpath/native/jni/java-util/Makefile.in,
classpath/native/jni/midi-alsa/Makefile.in,
classpath/native/jni/java-lang/Makefile.in,
classpath/native/jni/java-nio/Makefile.in,
classpath/native/jni/java-net/Makefile.in,
classpath/native/jni/xmlj/Makefile.in,
classpath/native/jni/qt-peer/Makefile.in,
classpath/native/jni/gtk-peer/Makefile.in,
classpath/native/Makefile.in, classpath/native/jawt/Makefile.in,
classpath/native/fdlibm/Makefile.in,
classpath/native/plugin/Makefile.in,
classpath/resource/Makefile.in, classpath/scripts/Makefile.in,
classpath/tools/Makefile.in, classpath/doc/Makefile.in,
classpath/doc/api/Makefile.in, classpath/lib/Makefile.in,
classpath/external/Makefile.in, classpath/external/jsr166/Makefile.in,
classpath/external/sax/Makefile.in,
classpath/external/w3c_dom/Makefile.in,
classpath/external/relaxngDatatype/Makefile.in,
classpath/include/Makefile.in,
classpath/examples/Makefile.in: Regenerate.
* classpath/config.guess, classpath/config.sub,
classpath/ltmain.sh : Update.
* classpath/configure, classpath/depcomp, classpath/missing,
classpath/aclocal.m4, classpath/install-sh: Regenerate.
* gnu/classpath/Configuration.java (CLASSPATH_VERSION): Now 0.95.
* sources.am: Regenerate.
* Makefile.in: Regenerate.
* Update the .class files and generated CNI header files, add new
.class and generated CNI header files.
* Remove generated files for removed java source files:
classpath/gnu/java/net/BASE64.java,
classpath/gnu/java/security/util/Base64.java,
classpath/gnu/java/awt/peer/gtk/GThreadMutex.java,
classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
classpath/gnu/java/awt/font/autofit/Scaler.java,
classpath/gnu/classpath/jdwp/util/Value.java,
classpath/gnu/javax/net/ssl/Base64.java.
* Remove empty directories.
* Makefile.am(nat_source_files): Add natVMOperatingSystemMXBeanImpl.cc.
* java/lang/Class.java(setAccessible): Merge from classpath.
* java/util/Locale.java: Remove.
* gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java,
gnu/java/lang/management/natVMOperatingSystemMXBeanImpl.cc: New.
* gcj/javaprims.h: Update class declarations.
* scripts/classes.pl: Update usage.
* HACKING: Mention to build all peers.
From-SVN: r125302
Diffstat (limited to 'libjava/classpath/vm/reference')
9 files changed, 386 insertions, 167 deletions
diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMFrame.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMFrame.java index cd21302..eec7b63 100644 --- a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMFrame.java +++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMFrame.java @@ -40,6 +40,7 @@ exception statement from your version. */ package gnu.classpath.jdwp; import gnu.classpath.jdwp.util.Location; +import gnu.classpath.jdwp.value.Value; /** * Reference implementation of VM hooks for JDWP Frame access. @@ -53,6 +54,9 @@ public class VMFrame * Returns the size of a frame ID over JDWP */ public static final int SIZE = 8; + + //The thread this frame resides in + private Thread thread; // The object this frame resides in private Object obj; @@ -64,6 +68,20 @@ public class VMFrame private long id; /** + * Create a new VMFrame object. + * + * @param thr a Thread, the thread this frame is in + * @param frame_id a long, the jframeID of this frame + * @param frame_loc a Location, the location of this frame + */ + public VMFrame(Thread thr, long frame_id, Location frame_loc) + { + thread = thr; + id = frame_id; + loc = frame_loc; + } + + /** * Gets the current location of the frame. */ public Location getLocation() @@ -76,14 +94,22 @@ public class VMFrame * * @param slot the slot containing the variable */ - public native Object getValue(int slot); + public native Value getValue(int slot, byte sig); /** * Assigns the given variable to the given value. * @param slot The slot which contains the variable * @param value The value to assign the variable to */ - public native void setValue(int slot, Object value); + public native void setValue(int slot, Value value); + + /** + * Get the thread this frame is in. + */ + public Thread getThread() + { + return thread; + } /** * Get the object which is represented by 'this' in the context of the frame, diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java index 8d423e9..9360e76 100644 --- a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java +++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java @@ -337,6 +337,10 @@ public class VMIdManager */ public ObjectId getObjectId (Object theObject) { + // Special case: null + if (theObject == null) + return new NullObjectId (); + ReferenceKey ref = new ReferenceKey (theObject, _refQueue); ObjectId id = (ObjectId) _oidTable.get (ref); if (id == null) @@ -364,6 +368,10 @@ public class VMIdManager public ObjectId get (long id) throws InvalidObjectException { + // Special case: null + if (id == 0) + return new NullObjectId (); + ObjectId oid = (ObjectId) _idTable.get (new Long (id)); if (oid == null) throw new InvalidObjectException (id); diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java index d861606..5c76194 100644 --- a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java +++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java @@ -1,7 +1,7 @@ /* VMVirtualMachine.java -- A reference implementation of a JDWP virtual machine - Copyright (C) 2005, 2006 Free Software Foundation + Copyright (C) 2005, 2006, 2007 Free Software Foundation This file is part of GNU Classpath. @@ -45,10 +45,12 @@ import gnu.classpath.jdwp.event.EventRequest; import gnu.classpath.jdwp.exception.InvalidMethodException; import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.util.MethodResult; +import gnu.classpath.jdwp.util.MonitorInfo; + import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Iterator; +import java.util.Collection; /** * A virtual machine according to JDWP. @@ -57,18 +59,35 @@ import java.util.Iterator; */ public class VMVirtualMachine { + // VM Capabilities + public static final boolean canWatchFieldModification = false; + public static final boolean canWatchFieldAccess = false; + public static final boolean canGetBytecodes = false; + public static final boolean canGetSyntheticAttribute = false; + public static final boolean canGetOwnedMonitorInfo = false; + public static final boolean canGetCurrentContendedMonitor = false; + public static final boolean canGetMonitorInfo = false; + public static final boolean canRedefineClasses = false; + public static final boolean canAddMethod = false; + public static final boolean canUnrestrictedlyRedefineClasses = false; + public static final boolean canPopFrames = false; + public static final boolean canUseInstanceFilters = false; + public static final boolean canGetSourceDebugExtension = false; + public static final boolean canRequestVMDeathEvent = false; + public static final boolean canSetDefaultStratum = false; + /** * Suspend a thread * * @param thread the thread to suspend */ - public static native void suspendThread (Thread thread) + public static native void suspendThread(Thread thread) throws JdwpException; /** * Suspend all threads */ - public static void suspendAllThreads () + public static void suspendAllThreads() throws JdwpException { // Our JDWP thread group -- don't suspend any of those threads @@ -115,7 +134,7 @@ public class VMVirtualMachine * * @param thread the thread to resume */ - public static native void resumeThread (Thread thread) + public static native void resumeThread(Thread thread) throws JdwpException; /** @@ -123,7 +142,7 @@ public class VMVirtualMachine * suspend count. It can not be used to force the application * to run. */ - public static void resumeAllThreads () + public static void resumeAllThreads() throws JdwpException { // Our JDWP thread group -- don't resume @@ -166,19 +185,13 @@ public class VMVirtualMachine * @param thread the thread whose suspend count is desired * @return the number of times the thread has been suspended */ - public static native int getSuspendCount (Thread thread) + public static native int getSuspendCount(Thread thread) throws JdwpException; /** - * Returns a count of the number of loaded classes in the VM - */ - public static native int getAllLoadedClassesCount () - throws JdwpException; - - /** - * Returns an iterator over all the loaded classes in the VM + * Returns a Collection of all classes loaded in the VM */ - public static native Iterator getAllLoadedClasses () + public static native Collection getAllLoadedClasses() throws JdwpException; /** @@ -188,7 +201,7 @@ public class VMVirtualMachine * @return a flag containing the class's status * @see JdwpConstants.ClassStatus */ - public static native int getClassStatus (Class clazz) + public static native int getClassStatus(Class clazz) throws JdwpException; /** @@ -198,7 +211,7 @@ public class VMVirtualMachine * @param klass the class whose methods are desired * @return an array of virtual machine methods */ - public static native VMMethod[] getAllClassMethods (Class klass) + public static native VMMethod[] getAllClassMethods(Class klass) { return null; } /** @@ -223,7 +236,7 @@ public class VMVirtualMachine * @param length number of frames to return (-1 for all frames) * @return a list of frames */ - public static native ArrayList getFrames (Thread thread, int start, + public static native ArrayList getFrames(Thread thread, int start, int length) throws JdwpException; @@ -237,7 +250,7 @@ public class VMVirtualMachine * @param bb buffer containing the frame's ID * @return the desired frame */ - public static native VMFrame getFrame (Thread thread, ByteBuffer bb) + public static native VMFrame getFrame(Thread thread, long frameID) throws JdwpException; /** @@ -246,7 +259,7 @@ public class VMVirtualMachine * @param thread the thread for which to get a frame count * @return the number of frames in the thread's stack */ - public static native int getFrameCount (Thread thread) + public static native int getFrameCount(Thread thread) throws JdwpException; @@ -257,7 +270,7 @@ public class VMVirtualMachine * @return integer status of the thread * @see JdwpConstants.ThreadStatus */ - public static native int getThreadStatus (Thread thread) + public static native int getThreadStatus(Thread thread) throws JdwpException; /** @@ -267,7 +280,7 @@ public class VMVirtualMachine * @param cl the class loader * @return a list of all visible classes */ - public static native ArrayList getLoadRequests (ClassLoader cl) + public static native ArrayList getLoadRequests(ClassLoader cl) throws JdwpException; /** @@ -282,7 +295,7 @@ public class VMVirtualMachine * (instance methods only) " * @return a result object containing the results of the invocation */ - public static native MethodResult executeMethod (Object obj, Thread thread, + public static native MethodResult executeMethod(Object obj, Thread thread, Class clazz, Method method, Object[] values, boolean nonVirtual) @@ -295,7 +308,7 @@ public class VMVirtualMachine * @return a string containing the source file name; "no path information * for the file is included" */ - public static native String getSourceFile (Class clazz) + public static native String getSourceFile(Class clazz) throws JdwpException; /** @@ -307,7 +320,7 @@ public class VMVirtualMachine * or do some internal work to set up the event notification (useful for * execution-related events like breakpoints, single-stepping, etc.). */ - public static native void registerEvent (EventRequest request) + public static native void registerEvent(EventRequest request) throws JdwpException; /** @@ -315,7 +328,7 @@ public class VMVirtualMachine * * @param request the request to unregister */ - public static native void unregisterEvent (EventRequest request) + public static native void unregisterEvent(EventRequest request) throws JdwpException; @@ -324,6 +337,88 @@ public class VMVirtualMachine * * @param kind the type of events to clear */ - public static native void clearEvents (byte kind) + public static native void clearEvents(byte kind) throws JdwpException; + + /** + * Redefines the given types. VM must support canRedefineClasses + * capability (may also require canAddMethod and/or + * canUnrestrictedlyRedefineClasses capabilities) + * + * @param types the classes to redefine + * @param bytecodes the new bytecode definitions for the classes + */ + public static native void redefineClasses(Class[] types, byte[][] bytecodes) + throws JdwpException; + + /** + * Sets the default stratum. VM must support the + * canSetDefaultStratum capability. + * + * @param stratum the new default stratum or empty string to + * use the reference default + */ + public static native void setDefaultStratum(String stratum) + throws JdwpException; + + /** + * Returns the source debug extension. VM must support the + * canGetSourceDebugExtension capability. + * + * @param klass the class for which to return information + * @returns the source debug extension + */ + public static native String getSourceDebugExtension(Class klass) + throws JdwpException; + + /** + * Returns the bytecode for the given method. VM must support the + * canGetBytecodes capability. + * + * @param method the method for which to get bytecodes + * @returns the bytecodes + */ + public static native byte[] getBytecodes(VMMethod method) + throws JdwpException; + + /** + * Returns monitor information about an object. VM must support + * the canGetMonitorInformation capability. + * + * @param obj the object + * @returns monitor information (owner, entry count, waiters) + */ + public static native MonitorInfo getMonitorInfo(Object obj) + throws JdwpException; + + /** + * Returns a list of owned monitors. VM must support the + * canGetOwnedMonitorInfo capability. + * + * @param thread a thread + * @returns the list of monitors owned by this thread + */ + public static native Object[] getOwnedMonitors(Thread thread) + throws JdwpException; + + /** + * Returns the current contended monitor for a thread. VM must + * support canGetCurrentContendedMonitor capability. + * + * @param thread the thread + * @returns the contended monitor + */ + public static native Object getCurrentContendedMonitor(Thread thread) + throws JdwpException; + + /** + * Pop all frames up to and including the given frame. VM must + * support canPopFrames capability. It is the responsibility + * of the VM to check if the thread is suspended. If it is not, + * the VM should throw ThreadNotSuspendedException. + * + * @param thread the thread + * @param frame the frame ID + */ + public static native void popFrames(Thread thread, long frameId); } diff --git a/libjava/classpath/vm/reference/gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java b/libjava/classpath/vm/reference/gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java new file mode 100644 index 0000000..20b3f9e --- /dev/null +++ b/libjava/classpath/vm/reference/gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java @@ -0,0 +1,68 @@ +/* VMOperatingSystemMXBeanImpl.java - VM implementation of an OS bean + Copyright (C) 2006 Free Software Foundation + +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.lang.management; + +import gnu.classpath.Configuration; + +/** + * Provides access to information about the operating system. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.6 + */ +final class VMOperatingSystemMXBeanImpl +{ + + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javalangmanagement"); + } + } + + /** + * Returns the system load average from the last + * minute. + * + * @return the system load average from the last + * minute. + */ + static native double getSystemLoadAverage(); + +} diff --git a/libjava/classpath/vm/reference/gnu/java/lang/management/VMThreadMXBeanImpl.java b/libjava/classpath/vm/reference/gnu/java/lang/management/VMThreadMXBeanImpl.java index c5bcb63..1c061aa 100644 --- a/libjava/classpath/vm/reference/gnu/java/lang/management/VMThreadMXBeanImpl.java +++ b/libjava/classpath/vm/reference/gnu/java/lang/management/VMThreadMXBeanImpl.java @@ -60,6 +60,16 @@ final class VMThreadMXBeanImpl /** * Returns the ids of cycles of deadlocked threads, occurring + * due to monitor ownership or ownable synchronizer ownership. + * This will only be called if ownable synchronizer monitoring + * is supported. + * + * @return the ids of the deadlocked threads. + */ + static native long[] findDeadlockedThreads(); + + /** + * Returns the ids of cycles of deadlocked threads, occurring * due to monitor ownership. * * @return the ids of the deadlocked threads. @@ -138,6 +148,25 @@ final class VMThreadMXBeanImpl } /** + * Fill out the given {@link ThreadInfo} object + * with ownable synchronizer usage information. + * This is only called if ownable synchronizer + * usage monitoring is supported. + * + * @param info the {@link ThreadInfo} object to modify. + */ + static native void getLockInfo(ThreadInfo info); + + /** + * Fill out the given {@link ThreadInfo} object + * with monitor usage information. This is only + * called if monitor usage monitoring is supported. + * + * @param info the {@link ThreadInfo} object to modify. + */ + static native void getMonitorInfo(ThreadInfo info); + + /** * Returns the current peak number of live threads. * * @return the peak number of live threads. diff --git a/libjava/classpath/vm/reference/java/io/VMFile.java b/libjava/classpath/vm/reference/java/io/VMFile.java index 13d256d..4f708a4 100644 --- a/libjava/classpath/vm/reference/java/io/VMFile.java +++ b/libjava/classpath/vm/reference/java/io/VMFile.java @@ -116,6 +116,27 @@ final class VMFile */ static native boolean mkdir(String dirpath); + /** + * Set the read permission of the file. + */ + public static synchronized native boolean setReadable(String path, + boolean readable, + boolean ownerOnly); + + /** + * Set the write permission of the file. + */ + public static synchronized native boolean setWritable(String path, + boolean writable, + boolean ownerOnly); + + /** + * Set the execute permission of the file. + */ + public static synchronized native boolean setExecutable(String path, + boolean executable, + boolean ownerOnly); + /* * This native method does the actual check of whether or not a file * is a plain file or not. It also handles the existence check to @@ -127,7 +148,7 @@ final class VMFile * This native method checks file permissions for writing */ static synchronized native boolean canWrite(String path); - + /** * This methods checks if a directory can be written to. */ @@ -150,6 +171,11 @@ final class VMFile */ static synchronized native boolean canRead(String path); + /** + * This native method checks file permissions for execution + */ + static synchronized native boolean canExecute(String path); + /* * This method does the actual check of whether or not a file is a * directory or not. It also handle the existence check to eliminate diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Method.java b/libjava/classpath/vm/reference/java/lang/reflect/Method.java index c520f05..2db59fe 100644 --- a/libjava/classpath/vm/reference/java/lang/reflect/Method.java +++ b/libjava/classpath/vm/reference/java/lang/reflect/Method.java @@ -1,5 +1,5 @@ /* java.lang.reflect.Method - reflection of Java methods - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2002, 2005, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -449,4 +449,17 @@ extends AccessibleObject implements Member, GenericDeclaration MethodSignatureParser p = new MethodSignatureParser(this, sig); return p.getGenericReturnType(); } + + /** + * If this method is an annotation method, returns the default + * value for the method. If there is no default value, or if the + * method is not a member of an annotation type, returns null. + * Primitive types are wrapped. + * + * @throws TypeNotPresentException if the method returns a Class, + * and the class cannot be found + * + * @since 1.5 + */ + public native Object getDefaultValue(); } diff --git a/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java b/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java index 7f1e3ad..e28e616 100644 --- a/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java +++ b/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java @@ -43,7 +43,6 @@ import gnu.classpath.Configuration; import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Set; -import java.util.Vector; /** * This class models a network interface on the host computer. A network @@ -58,12 +57,12 @@ import java.util.Vector; final class VMNetworkInterface { String name; - Set addresses; + Set<InetAddress> addresses; VMNetworkInterface(String name) { this.name = name; - addresses = new HashSet(); + addresses = new HashSet<InetAddress>(); } /** @@ -72,7 +71,7 @@ final class VMNetworkInterface */ public VMNetworkInterface() { - addresses = new HashSet(); + addresses = new HashSet<InetAddress>(); try { addresses.add(InetAddress.getByName("0.0.0.0")); diff --git a/libjava/classpath/vm/reference/java/util/VMTimeZone.java b/libjava/classpath/vm/reference/java/util/VMTimeZone.java index 86b6258..992ecaf 100644 --- a/libjava/classpath/vm/reference/java/util/VMTimeZone.java +++ b/libjava/classpath/vm/reference/java/util/VMTimeZone.java @@ -1,5 +1,5 @@ /* java.util.VMTimeZone - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,6 +40,9 @@ exception statement from your version. */ package java.util; import gnu.classpath.Configuration; +import gnu.classpath.SystemProperties; +import gnu.java.util.ZoneInfo; +import java.util.TimeZone; import java.io.*; @@ -75,9 +78,10 @@ final class VMTimeZone * The reference implementation which is made for GNU/Posix like * systems calls <code>System.getenv("TZ")</code>, * <code>readTimeZoneFile("/etc/timezone")</code>, - * <code>readtzFile("/etc/localtime")</code> and finally - * <code>getSystemTimeZoneId()</code> till a supported TimeZone is - * found through <code>TimeZone.getDefaultTimeZone(String)</code>. + * <code>ZoneInfo.readTZFile((String)null, "/etc/localtime")</code> + * and finally <code>getSystemTimeZoneId()</code> till a supported + * TimeZone is found through + * <code>TimeZone.getDefaultTimeZone(String)</code>. * If every method fails <code>null</code> is returned (which means * the TimeZone code will fall back on GMT as default time zone). * <p> @@ -108,9 +112,51 @@ final class VMTimeZone // Try to parse /etc/localtime if (zone == null) { - tzid = readtzFile("/etc/localtime"); - if (tzid != null && !tzid.equals("")) - zone = TimeZone.getDefaultTimeZone(tzid); + zone = ZoneInfo.readTZFile((String) null, "/etc/localtime"); + if (zone != null) + { + // Try to find a more suitable ID for the /etc/localtime + // timezone. + // Sometimes /etc/localtime is a symlink to some + // /usr/share/zoneinfo/ file. + String id = null; + try + { + id = new File("/etc/localtime").getCanonicalPath(); + if (id != null) + { + String zoneinfo_dir + = SystemProperties.getProperty("gnu.java.util.zoneinfo.dir"); + if (zoneinfo_dir != null) + zoneinfo_dir + = new File(zoneinfo_dir + + File.separatorChar).getCanonicalPath(); + if (zoneinfo_dir != null && id.startsWith(zoneinfo_dir)) + { + int pos = zoneinfo_dir.length(); + while (pos < id.length() + && id.charAt(pos) == File.separatorChar) + pos++; + if (pos < id.length()) + id = id.substring(pos); + else + id = null; + } + else + id = null; + } + } + catch (IOException ioe) + { + id = null; + } + + if (id == null) + id = readSysconfigClockFile("/etc/sysconfig/clock"); + + if (id != null) + zone.setID(id); + } } // Try some system specific way @@ -186,121 +232,46 @@ final class VMTimeZone } /** - * Tries to read a file as a "standard" tzfile and return a time - * zone id string as expected by <code>getDefaultTimeZone(String)</code>. - * If the file doesn't exist, an IOException occurs or it isn't a tzfile - * that can be parsed null is returned. - * <p> - * The tzfile structure (as also used by glibc) is described in the Olson - * tz database archive as can be found at - * <code>ftp://elsie.nci.nih.gov/pub/</code>. + * Tries to read the time zone name from a file. + * If the file cannot be read or an IOException occurs null is returned. * <p> - * At least the following platforms support the tzdata file format - * and /etc/localtime (GNU/Linux, Darwin, Solaris and FreeBSD at - * least). Some systems (like Darwin) don't start the file with the - * required magic bytes 'TZif', this implementation can handle - * that). + * The /etc/sysconfig/clock file is not standard, but a lot of systems + * have it. The file is included by shell scripts and the timezone + * name is defined in ZONE variable. + * This routine should grok it with or without quotes: + * ZONE=America/New_York + * or + * ZONE="Europe/London" */ - private static String readtzFile(String file) + private static String readSysconfigClockFile(String file) { - File f = new File(file); - if (!f.exists()) - return null; - - DataInputStream dis = null; + BufferedReader br = null; try { - FileInputStream fis = new FileInputStream(f); - BufferedInputStream bis = new BufferedInputStream(fis); - dis = new DataInputStream(bis); - - // Make sure we are reading a tzfile. - byte[] tzif = new byte[4]; - dis.readFully(tzif); - if (tzif[0] == 'T' && tzif[1] == 'Z' - && tzif[2] == 'i' && tzif[3] == 'f') - // Reserved bytes, ttisgmtcnt, ttisstdcnt and leapcnt - skipFully(dis, 16 + 3 * 4); - else - // Darwin has tzdata files that don't start with the TZif marker - skipFully(dis, 16 + 3 * 4 - 4); - - int timecnt = dis.readInt(); - int typecnt = dis.readInt(); - if (typecnt > 0) + FileInputStream fis = new FileInputStream(file); + BufferedInputStream bis = new BufferedInputStream(fis); + br = new BufferedReader(new InputStreamReader(bis)); + + for (String line = br.readLine(); line != null; line = br.readLine()) { - int charcnt = dis.readInt(); - // Transition times plus indexed transition times. - skipFully(dis, timecnt * (4 + 1)); - - // Get last gmt_offset and dst/non-dst time zone names. - int abbrind = -1; - int dst_abbrind = -1; - int gmt_offset = 0; - while (typecnt-- > 0) - { - // gmtoff - int offset = dis.readInt(); - int dst = dis.readByte(); - if (dst == 0) - { - abbrind = dis.readByte(); - gmt_offset = offset; - } - else - dst_abbrind = dis.readByte(); - } - - // gmt_offset is the offset you must add to UTC/GMT to - // get the local time, we need the offset to add to - // the local time to get UTC/GMT. - gmt_offset *= -1; - - // Turn into hours if possible. - if (gmt_offset % 3600 == 0) - gmt_offset /= 3600; - - if (abbrind >= 0) + line = line.trim(); + if (line.length() < 8 || !line.startsWith("ZONE=")) + continue; + int posstart = 6; + int posend; + if (line.charAt(5) == '"') + posend = line.indexOf('"', 6); + else if (line.charAt(5) == '\'') + posend = line.indexOf('\'', 6); + else { - byte[] names = new byte[charcnt]; - dis.readFully(names); - int j = abbrind; - while (j < charcnt && names[j] != 0) - j++; - - String zonename = new String(names, abbrind, j - abbrind, - "ASCII"); - - String dst_zonename; - if (dst_abbrind >= 0) - { - j = dst_abbrind; - while (j < charcnt && names[j] != 0) - j++; - dst_zonename = new String(names, dst_abbrind, - j - dst_abbrind, "ASCII"); - } - else - dst_zonename = ""; - - // Only use gmt offset when necessary. - // Also special case GMT+/- timezones. - String offset_string; - if ("".equals(dst_zonename) - && (gmt_offset == 0 - || zonename.startsWith("GMT+") - || zonename.startsWith("GMT-"))) - offset_string = ""; - else - offset_string = Integer.toString(gmt_offset); - - String id = zonename + offset_string + dst_zonename; - - return id; + posstart = 5; + posend = line.length(); } + if (posend < 0) + return null; + return line.substring(posstart, posend); } - - // Something didn't match while reading the file. return null; } catch (IOException ioe) @@ -312,31 +283,15 @@ final class VMTimeZone { try { - if (dis != null) - dis.close(); + if (br != null) + br.close(); } - catch(IOException ioe) + catch (IOException ioe) { // Error while close, nothing we can do. } } } - - /** - * Skips the requested number of bytes in the given InputStream. - * Throws EOFException if not enough bytes could be skipped. - * Negative numbers of bytes to skip are ignored. - */ - private static void skipFully(InputStream is, long l) throws IOException - { - while (l > 0) - { - long k = is.skip(l); - if (k <= 0) - throw new EOFException(); - l -= k; - } - } /** * Tries to get the system time zone id through native code. |