diff options
| author | Jing Yu <jingyu@google.com> | 2009-11-05 15:11:04 -0800 |
|---|---|---|
| committer | Jing Yu <jingyu@google.com> | 2009-11-05 15:11:04 -0800 |
| commit | df62c1c110e8532b995b23540b7e3695729c0779 (patch) | |
| tree | dbbd4cbdb50ac38011e058a2533ee4c3168b0205 /gcc-4.2.1/libjava/gnu/classpath | |
| parent | 8d401cf711539af5a2f78d12447341d774892618 (diff) | |
| download | toolchain_gcc-df62c1c110e8532b995b23540b7e3695729c0779.tar.gz toolchain_gcc-df62c1c110e8532b995b23540b7e3695729c0779.tar.bz2 toolchain_gcc-df62c1c110e8532b995b23540b7e3695729c0779.zip | |
Check in gcc sources for prebuilt toolchains in Eclair.
Diffstat (limited to 'gcc-4.2.1/libjava/gnu/classpath')
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/SystemProperties.java | 157 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/VMFrame.java | 106 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/VMIdManager.java | 427 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/VMMethod.java | 178 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/VMVirtualMachine.java | 335 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMFrame.cc | 26 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMMethod.cc | 47 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc | 347 | ||||
| -rw-r--r-- | gcc-4.2.1/libjava/gnu/classpath/natSystemProperties.cc | 422 |
9 files changed, 2045 insertions, 0 deletions
diff --git a/gcc-4.2.1/libjava/gnu/classpath/SystemProperties.java b/gcc-4.2.1/libjava/gnu/classpath/SystemProperties.java new file mode 100644 index 000000000..001663f0b --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/SystemProperties.java @@ -0,0 +1,157 @@ +/* SystemProperties.java -- Manage the System properties. + Copyright (C) 2004, 2005 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.classpath; + +import java.util.Properties; + +/** + * The class manages the System properties. This class is only available to + * privileged code (i.e. code loaded by the bootstrap class loader) and + * therefore doesn't do any security checks. + * This class is separated out from java.lang.System to simplify bootstrap + * dependencies and to allow trusted code a simple and efficient mechanism + * to access the system properties. + */ +public class SystemProperties +{ + /** + * Stores the current system properties. This can be modified by + * {@link #setProperties(Properties)}, but will never be null, because + * setProperties(null) sucks in the default properties. + */ + private static Properties properties; + + /** + * The default properties. Once the default is stabilized, + * it should not be modified; + * instead it is cloned when calling <code>setProperties(null)</code>. + */ + private static final Properties defaultProperties = new Properties(); + + private static native void insertSystemProperties(Properties properties); + + static + { + insertSystemProperties(defaultProperties); + + defaultProperties.put("gnu.classpath.version", + Configuration.CLASSPATH_VERSION); + + // Set base URL if not already set. + if (defaultProperties.get("gnu.classpath.home.url") == null) + defaultProperties.put("gnu.classpath.home.url", + "file://" + + defaultProperties.get("gnu.classpath.home") + + "/lib"); + + // Set short name if not already set. + if (defaultProperties.get("gnu.classpath.vm.shortname") == null) + { + String value = defaultProperties.getProperty("java.vm.name"); + int index = value.lastIndexOf(' '); + if (index != -1) + value = value.substring(index + 1); + defaultProperties.put("gnu.classpath.vm.shortname", value); + } + + // Network properties + if (defaultProperties.get("http.agent") == null) + { + String userAgent = ("gnu-classpath/" + + defaultProperties.getProperty("gnu.classpath.version") + + " (" + + defaultProperties.getProperty("gnu.classpath.vm.shortname") + + "/" + + defaultProperties.getProperty("java.vm.version") + + ")"); + defaultProperties.put("http.agent", userAgent); + } + + defaultProperties.put("gnu.cpu.endian", + isWordsBigEndian() ? "big" : "little"); + + // XXX FIXME - Temp hack for old systems that set the wrong property + if (defaultProperties.get("java.io.tmpdir") == null) + defaultProperties.put("java.io.tmpdir", + defaultProperties.get("java.tmpdir")); + + // Note that we use clone here and not new. Some programs assume + // that the system properties do not have a parent. + properties = (Properties) defaultProperties.clone(); + } + + public static String getProperty(String name) + { + return properties.getProperty(name); + } + + public static String getProperty(String name, String defaultValue) + { + return properties.getProperty(name, defaultValue); + } + + public static String setProperty(String name, String value) + { + return (String) properties.setProperty(name, value); + } + + public static Properties getProperties() + { + return properties; + } + + public static void setProperties(Properties properties) + { + if (properties == null) + { + // Note that we use clone here and not new. Some programs + // assume that the system properties do not have a parent. + properties = (Properties)defaultProperties.clone(); + } + + SystemProperties.properties = properties; + } + + /** + * Detect big-endian systems. + * + * @return true if the system is big-endian. + */ + private static native boolean isWordsBigEndian(); +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMFrame.java b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMFrame.java new file mode 100644 index 000000000..cd213025a --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMFrame.java @@ -0,0 +1,106 @@ +/* VMFrame.java -- Reference implementation of VM hooks for JDWP Frame access. + Copyright (C) 2005, 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 +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.classpath.jdwp; + +import gnu.classpath.jdwp.util.Location; + +/** + * Reference implementation of VM hooks for JDWP Frame access. + * + * @author aluchko + */ + +public class VMFrame +{ + /** + * Returns the size of a frame ID over JDWP + */ + public static final int SIZE = 8; + + // The object this frame resides in + private Object obj; + + // The current location of this frame + private Location loc; + + // id of this frame + private long id; + + /** + * Gets the current location of the frame. + */ + public Location getLocation() + { + return loc; + } + + /** + * Returns the value of the variable in the given slot. + * + * @param slot the slot containing the variable + */ + public native Object getValue(int slot); + + /** + * 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); + + /** + * Get the object which is represented by 'this' in the context of the frame, + * returns null if the method is native or static. + */ + public Object getObject() + { + return obj; + } + + /** + * Get the frameID + * @return an id which is unique within the scope of the VM + */ + public long getId() + { + return id; + } + +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMIdManager.java b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMIdManager.java new file mode 100644 index 000000000..8d423e9b0 --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMIdManager.java @@ -0,0 +1,427 @@ +/* VMIdManager.java -- A reference/example implementation of a manager for + JDWP object/reference type IDs + + Copyright (C) 2005, 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 +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.classpath.jdwp; + +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.id.*; + +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Hashtable; + +/** + * This class manages objects and referencetypes that are reported + * to the debugger. All objects and referencetypes reported to the + * debugger should go through this manager. + * + * A brief summary of what an <code>IdManager</code> must provide: + * + * <code> + * public ObjectId getObjectId (Object theObject); + * public ObjectId get (long id); + * public ObjectId readObjectId (ByteBuffer bb); + * public ReferenceTypeId getReferenceTypeId (Class clazz); + * public ReferenceTypeId getReferenceType (long id); + * public ReferenceTypeId readReferenceTypeId (ByteBuffer bb); + * </code> + * + * See the javadoc on these methods later in this file for more + * information on these functions. + * + * <b>NOTE:</b> All IDs handled by the ID manager (all object and reference + * type IDs) are assumed to be of type <code>long</code>. + * + * <b>NOTE:</b> This class does not manage virtual machine-specific types, + * like methods, fields, and frames. These already have unique IDs within + * the virtual machine and do not need further abstraction here. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VMIdManager +{ + // This factory generates ids for objects and types that may + // be sent to a debugger. + private static class IdFactory + { + // ID of last object / referencetype + private static Object _idLock = new Object (); + private static Object _ridLock = new Object (); + private static long _lastId = 0; + private static long _lastRid = 0; + + // A list of all ID types + private static HashMap _idList = new HashMap (); + + // Initialize the id list with known types + static + { + // ObjectId and ArrayId are special cases. See newObjectId. + _idList.put (ClassLoaderId.typeClass, ClassLoaderId.class); + _idList.put (ClassObjectId.typeClass, ClassObjectId.class); + _idList.put (StringId.typeClass, StringId.class); + _idList.put (ThreadId.typeClass, ThreadId.class); + _idList.put (ThreadGroupId.typeClass, ThreadGroupId.class); + } + + /** + * Returns a new id for the given object + * + * @param obj SoftReference of the object for which an id is desired + * @returns a suitable object id + */ + public static ObjectId newObjectId (SoftReference obj) + { + ObjectId id = null; + Object object = obj.get (); + + // Special case: arrays + if (object.getClass ().isArray ()) + id = new ArrayId (); + else + { + // Loop through all classes until we hit baseclass + Class myClass; + for (myClass = object.getClass (); myClass != null; + myClass = myClass.getSuperclass ()) + { + Class clz = (Class) _idList.get (myClass); + if (clz != null) + { + try + { + id = (ObjectId) clz.newInstance (); + synchronized (_idLock) + { + id.setId (++_lastId); + } + id.setReference (obj); + return id; + } + catch (InstantiationException ie) + { + // This really should not happen + throw new RuntimeException ("cannot create new ID", ie); + } + catch (IllegalAccessException iae) + { + // This really should not happen + throw new RuntimeException ("illegal access of ID", iae); + } + } + } + + /* getSuperclass returned null and no matching ID type found. + So it must derive from Object. */ + id = new ObjectId (); + } + + synchronized (_idLock) + { + id.setId (++_lastId); + } + id.setReference (obj); + return id; + } + + /** + * Returns a new reference type id for the given class + * + * @param ref SoftReference to the desired type + * @returns a suitable reference type id or null when the + * reference is cleared. + */ + public static ReferenceTypeId newReferenceTypeId (SoftReference ref) + { + ReferenceTypeId id; + Class clazz = (Class) ref.get (); + if (clazz == null) + return null; + + if (clazz.isArray ()) + id = new ArrayReferenceTypeId (); + else if (clazz.isInterface ()) + id = new InterfaceReferenceTypeId (); + else + id = new ClassReferenceTypeId (); + id.setReference (ref); + synchronized (_ridLock) + { + id.setId (++_lastRid); + } + return id; + } + } + + /** + * This class is a SoftReferenceIdentity type that is used by + * the ID manager. + */ + class ReferenceKey extends SoftReference + { + // Hash code of referent + private int _hash; + + /** + * Constructs a new <code>ReferenceKey</code> object + * with the given referent. + * + * <p>This constructor should only be used for object lookups + * by the backend. + * + * @param referent the object to reference + */ + public ReferenceKey (Object referent) + { + super (referent); + _hash = referent.hashCode (); + } + + /** + * Constructs a new <code>ReferenceKey</code> object + * with the given referent and reference queue. + * + * <p>The JDWP back-end stores a <code>ReferenceKey</code> + * with its corresponding <code>JdwpId</code>. This constructor + * is used by the back-end when adding new IDs to be managed. + * + * @param referent the object to reference + * @param queue the queue to which to report garbage collections + */ + public ReferenceKey (Object referent, ReferenceQueue queue) + { + super (referent, queue); + _hash = referent.hashCode (); + } + + /** + * Returns the hash code of the referent. + * This seems hacky, but is required in order to use this class + * as a hash table key. + * + * @returns the hash code of the referent + */ + public int hashCode () + { + return _hash; + } + + /** + * Comparator for keys + * + * This method can be used in two ways: + * + * <ol> + * <li>For table lookups, where we want to compare referents</li> + * <li>For clearing GCd objects, where we want to compare the actual + * key object (not the referent)</li> + * </ol> + */ + public boolean equals (Object obj) + { + if (obj instanceof ReferenceKey) + { + ReferenceKey ref = (ReferenceKey) obj; + + /* First check if the two references are the same. + If they are, that means we must be clearing GCd objects. */ + if (this == obj) + return true; + + return (ref.get () == get ()); + } + + return false; + } + } + + // instance of VMIdManager + private static VMIdManager _idm = new VMIdManager (); + + // A reference queue for our objects + private ReferenceQueue _refQueue; + + // Mapping of objects (ReferenceKey) to IDs (ObjectId) + private Hashtable _oidTable; + + // Mapping of ID numbers (Long) to IDs (ObjectId) + private Hashtable _idTable; + + /* Mapping of class (ReferenceKey) to IDs (ReferenceTypeId) for reference + types. Unlike other types, reference id types are NEVER released. */ + private Hashtable _classTable; + + // Mapping of ID numbers (Long) to reference type IDs (ReferenceTypeId) + private Hashtable _ridTable; + + /** + * Gets the instance of VMIdManager, constructing a new one + * if none currently exists. + */ + public static VMIdManager getDefault () + { + return _idm; + } + + // Constructs a new <code>IdManager</code> + private VMIdManager () + { + _refQueue = new ReferenceQueue (); + _oidTable = new Hashtable (50); + _idTable = new Hashtable (50); + _classTable = new Hashtable (20); + _ridTable = new Hashtable (20); + } + + // Updates the object ID table, removing IDs whose objects have + // been garbage collected. + private void _update () + { + Reference ref; + while ((ref = _refQueue.poll ()) != null) + { + ObjectId id = (ObjectId) _oidTable.get (ref); + _oidTable.remove (ref); + _idTable.remove (new Long (id.getId ())); + } + } + + /** + * Returns an id for the given object, adding it + * if it does not have an id. + * + * @param theObject the object to get an ID/add + * @returns the ID of the object + */ + public ObjectId getObjectId (Object theObject) + { + ReferenceKey ref = new ReferenceKey (theObject, _refQueue); + ObjectId id = (ObjectId) _oidTable.get (ref); + if (id == null) + { + // update the tables -- this is an arbitrary place to put this + _update (); + + // Object not found. Make new id for it + id = IdFactory.newObjectId (ref); + _oidTable.put (ref, id); + _idTable.put (new Long (id.getId ()), id); + } + + return id; + } + + /** + * Returns the <code>JdwpId</code> for a given ID. Unlike + * <code>getId</code>, it throws an exception if the ID is not + * known. + * + * @param id the numerical ID of the desired <code>JdwpId</code> + * @throws InvalidObjectException if the ID is not found + */ + public ObjectId get (long id) + throws InvalidObjectException + { + ObjectId oid = (ObjectId) _idTable.get (new Long (id)); + if (oid == null) + throw new InvalidObjectException (id); + + return oid; + } + + public ObjectId readObjectId (ByteBuffer bb) + throws InvalidObjectException + { + long id = bb.getLong (); + return get (id); + } + + /** + * Gets the reference type id for the given class, creating + * a new one if it does not already have an id + * + * @param clazz the class for which to get an ID + * @returns the ID of the class + */ + public ReferenceTypeId getReferenceTypeId (Class clazz) + { + ReferenceKey ref = new ReferenceKey (clazz); + ReferenceTypeId id = (ReferenceTypeId)_classTable.get (ref); + if (id == null) + { + // Object not found. Make new id for it + id = IdFactory.newReferenceTypeId (ref); + _classTable.put (ref, id); + _ridTable.put (new Long (id.getId ()), id); + } + + return id; + } + + /** + * Returns the <code>ReferenceTypeId</code> for a given ID. Unlike + * <code>getReferenceTypeId</code>, it throws an exception if the ID is not + * known. + * + * @param id the numerical ID of the desired reference type + * @throws InvalidClassException if the ID is not found + */ + public ReferenceTypeId getReferenceType (long id) + throws InvalidClassException + { + ReferenceTypeId rid = (ReferenceTypeId) _ridTable.get (new Long (id)); + if (rid == null) + throw new InvalidClassException (id); + + return rid; + } + + public ReferenceTypeId readReferenceTypeId (ByteBuffer bb) + throws InvalidClassException + { + long id = bb.getLong (); + return getReferenceType (id); + } +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMMethod.java b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMMethod.java new file mode 100644 index 000000000..d345bc1b5 --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMMethod.java @@ -0,0 +1,178 @@ +/* VMMethod.java -- a method in a virtual machine + Copyright (C) 2006 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 +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.classpath.jdwp; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.util.LineTable; +import gnu.classpath.jdwp.util.VariableTable; + +/** + * This class is really an amalgamation of two classes: one class + * represents a virtual machine method and the other represents + * the JDWP back-end's ID for the method. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VMMethod +{ + /** + * Returns the size of a JDWP method ID + * @see gnu.classpath.jdwp.id.JdwpId#SIZE + */ + public static final int SIZE = 8; + + // The class in which this method is declared + private Class _class; + + // The method's ID + private long _methodId; + + /** + * Constructs a new VMMethod object. This constructor is protected + * so that only the factory methods of VMVirtualMachine can be used + * to create VMMethods. + * + * @param klass the method's containing class + * @param id method identifier, e.g., jmethodID + * @see gnu.classpath.jdwp.VMVirtualMachine#getAllClassMethods + * @see gnu.classpath.jdwp.VMVirtualMachine#getClassMethod + */ + protected VMMethod(Class klass, long id) + { + _class = klass; + _methodId = id; + } + + /** + * Returns the internal method ID for this method + */ + public long getId() + { + return _methodId; + } + + /** + * Returns the method's declaring class + */ + public Class getDeclaringClass() + { + return _class; + } + + /** + * Returns the name of this method + */ + public native String getName(); + + /** + * Returns the signature of this method + */ + public native String getSignature(); + + /** + * Returns the method's modifier flags + */ + public native int getModifiers(); + + /** + * "Returns line number information for the method, if present. The line + * table maps source line numbers to the initial code index of the line. + * The line table is ordered by code index (from lowest to highest). The + * line number information is constant unless a new class definition is + * installed using RedefineClasses." + * + * @return the line table + * @throws JdwpException + */ + public native LineTable getLineTable() + throws JdwpException; + + /** + * "Returns variable information for the method. The variable table + * includes arguments and locals declared within the method. For instance + * methods, the "this" reference is included in the table. Also, synthetic + * variables may be present." + * + * @return the variable table + * @throws JdwpException + */ + public native VariableTable getVariableTable() + throws JdwpException; + + /** + * Returns a string representation of this method (not + * required but nice for debugging). + */ + public String toString() + { + return getDeclaringClass().getName() + "." + getName(); + } + + /** + * Writes the method's ID to the output stream + * + * @param ostream the output stream to which to write + * @throws IOException for any errors writing to the stream + * @see gnu.classpath.jdwp.id.JdwpId#write + */ + public void writeId(DataOutputStream ostream) + throws IOException + { + ostream.writeLong(getId()); + } + + /** + * Returns a VMMethod from the ID in the byte buffer + * + * @param klass the method's declaring class + * @param bb a ByteBuffer containing the method's ID + * @throws JdwpException for any errors creating the method + * @throws IOException for any errors reading from the buffer + */ + public static VMMethod readId(Class klass, ByteBuffer bb) + throws JdwpException, IOException + { + return VMVirtualMachine.getClassMethod(klass, bb.getLong()); + } +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMVirtualMachine.java b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMVirtualMachine.java new file mode 100644 index 000000000..5c4018fce --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/VMVirtualMachine.java @@ -0,0 +1,335 @@ +/* VMVirtualMachine.java -- A reference implementation of a JDWP virtual + machine + + Copyright (C) 2005, 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 +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.classpath.jdwp; + +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 java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; + +/** + * A virtual machine according to JDWP. + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class VMVirtualMachine +{ + // Thread suspension table. Maps Thread to suspend count (Integer) + private static Hashtable _jdwp_suspend_counts; + + public static native void initialize (); + + /** + * Suspend a thread + * + * @param thread the thread to suspend + */ + public static native void suspendThread (Thread thread) + throws JdwpException; + + /** + * Suspend all threads + */ + public static void suspendAllThreads () + throws JdwpException + { + // Our JDWP thread group -- don't suspend any of those threads + Thread current = Thread.currentThread (); + ThreadGroup jdwpGroup = Jdwp.getDefault().getJdwpThreadGroup(); + + // Find the root ThreadGroup + ThreadGroup group = jdwpGroup; + ThreadGroup parent = group.getParent (); + while (parent != null) + { + group = parent; + parent = group.getParent (); + } + + // Get all the threads in the system + int num = group.activeCount (); + Thread[] threads = new Thread[num]; + group.enumerate (threads); + + for (int i = 0; i < num; ++i) + { + Thread t = threads[i]; + if (t != null) + { + if (t.getThreadGroup () == jdwpGroup || t == current) + { + // Don't suspend the current thread or any JDWP thread + continue; + } + else + suspendThread (t); + } + } + + // Now suspend the current thread + if (current.getThreadGroup() != jdwpGroup) + suspendThread (current); + } + + /** + * Resume a thread. A thread must be resumed as many times + * as it has been suspended. + * + * @param thread the thread to resume + */ + public static native void resumeThread (Thread thread) + throws JdwpException; + + /** + * Resume all threads. This simply decrements the thread's + * suspend count. It can not be used to force the application + * to run. + */ + public static void resumeAllThreads () + throws JdwpException + { + // Our JDWP thread group -- don't resume + Thread current = Thread.currentThread (); + ThreadGroup jdwpGroup = current.getThreadGroup (); + + // Find the root ThreadGroup + ThreadGroup group = jdwpGroup; + ThreadGroup parent = group.getParent (); + while (parent != null) + { + group = parent; + parent = group.getParent (); + } + + // Get all the threads in the system + int num = group.activeCount (); + Thread[] threads = new Thread[num]; + group.enumerate (threads); + + for (int i = 0; i < num; ++i) + { + Thread t = threads[i]; + if (t != null) + { + if (t.getThreadGroup () == jdwpGroup || t == current) + { + // Don't resume the current thread or any JDWP thread + continue; + } + else + resumeThread (t); + } + } + } + + /** + * Get the suspend count for a give thread + * + * @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) + 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 + */ + public static native Iterator getAllLoadedClasses () + throws JdwpException; + + /** + * Returns the status of the given class + * + * @param clazz the class whose status is desired + * @return a flag containing the class's status + * @see JdwpConstants.ClassStatus + */ + public static native int getClassStatus (Class clazz) + throws JdwpException; + + /** + * Returns all of the methods defined in the given class. This + * includes all methods, constructors, and class initializers. + * + * @param klass the class whose methods are desired + * @return an array of virtual machine methods + */ + public static native VMMethod[] getAllClassMethods (Class klass) + throws JdwpException; + + /** + * A factory method for getting valid virtual machine methods + * which may be passed to/from the debugger. + * + * @param klass the class in which the method is defined + * @param id the ID of the desired method + * @return the desired internal representation of the method + * @throws InvalidMethodException if the method is not defined + * in the class + * @throws JdwpException for any other error + */ + public static native VMMethod getClassMethod(Class klass, long id) + throws JdwpException; + + /** + * Returns the thread's call stack + * + * @param thread thread for which to get call stack + * @param start index of first frame to return + * @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, + int length) + throws JdwpException; + + /** + * Returns the frame for a given thread with the frame ID in + * the buffer + * + * I don't like this. + * + * @param thread the frame's thread + * @param bb buffer containing the frame's ID + * @return the desired frame + */ + public static native VMFrame getFrame (Thread thread, ByteBuffer bb) + throws JdwpException; + + /** + * Returns the number of frames in the thread's stack + * + * @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) + throws JdwpException; + + + /** + * Returns the status of a thread + * + * @param thread the thread for which to get status + * @return integer status of the thread + * @see JdwpConstants.ThreadStatus + */ + public static native int getThreadStatus (Thread thread) + throws JdwpException; + + /** + * Returns a list of all classes which this class loader has been + * requested to load + * + * @param cl the class loader + * @return a list of all visible classes + */ + public static native ArrayList getLoadRequests (ClassLoader cl) + throws JdwpException; + + /** + * Executes a method in the virtual machine + * + * @param obj instance in which to invoke method (null for static) + * @param thread the thread in which to invoke the method + * @param clazz the class in which the method is defined + * @param method the method to invoke + * @param values arguments to pass to method + * @param nonVirtual "otherwise, normal virtual invoke + * (instance methods only) " + * @return a result object containing the results of the invocation + */ + public static native MethodResult executeMethod (Object obj, Thread thread, + Class clazz, Method method, + Object[] values, + boolean nonVirtual) + throws JdwpException; + + /** + * "Returns the name of source file in which a reference type was declared" + * + * @param clazz the class for which to return a source file + * @return a string containing the source file name; "no path information + * for the file is included" + */ + public static native String getSourceFile (Class clazz) + throws JdwpException; + + /** + * Register a request from the debugger + * + * Virtual machines have two options. Either do nothing and allow + * the event manager to take care of the request (useful for broadcast-type + * events like class prepare/load/unload, thread start/end, etc.) + * 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) + throws JdwpException; + + /** + * Unregisters the given request + * + * @param request the request to unregister + */ + public static native void unregisterEvent (EventRequest request) + throws JdwpException; + + + /** + * Clear all events of the given kind + * + * @param kind the type of events to clear + */ + public static native void clearEvents (byte kind) + throws JdwpException; +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMFrame.cc b/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMFrame.cc new file mode 100644 index 000000000..de3b844f4 --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMFrame.cc @@ -0,0 +1,26 @@ +// natFrame.cc -- native support for VMFrame.java + +/* Copyright (C) 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. */ + +#include <gcj/cni.h> + +#include <gnu/classpath/jdwp/VMFrame.h> + +using namespace java::lang; + +Object* +gnu::classpath::jdwp::VMFrame::getValue (jint slot) +{ + return 0; +} + +void +gnu::classpath::jdwp::VMFrame::setValue (jint slot, Object* value) +{ +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMMethod.cc b/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMMethod.cc new file mode 100644 index 000000000..eb1d6fda0 --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMMethod.cc @@ -0,0 +1,47 @@ +// natVMMethod.cc -- native support for VMMethod + +/* Copyright (C) 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. */ + +#include <config.h> +#include <gcj/cni.h> + +#include <gnu/classpath/jdwp/VMMethod.h> +#include <gnu/classpath/jdwp/util/LineTable.h> +#include <gnu/classpath/jdwp/util/VariableTable.h> + +java::lang::String* +gnu::classpath::jdwp::VMMethod::getName () +{ + return NULL; +} + +java::lang::String* +gnu::classpath::jdwp::VMMethod::getSignature () +{ + return NULL; +} + +jint +gnu::classpath::jdwp::VMMethod::getModifiers () +{ + return 0; +} + +gnu::classpath::jdwp::util::LineTable* +gnu::classpath::jdwp::VMMethod::getLineTable () +{ + return NULL; +} + + +gnu::classpath::jdwp::util::VariableTable* +gnu::classpath::jdwp::VMMethod::getVariableTable () +{ + return NULL; +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc b/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc new file mode 100644 index 000000000..5e790b965 --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc @@ -0,0 +1,347 @@ +// natVMVirtualMachine.cc - native support for VMVirtualMachine + +/* Copyright (C) 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. */ + +#include <config.h> +#include <gcj/cni.h> +#include <jvm.h> +#include <jvmti.h> + +#include <java/lang/Class.h> +#include <java/lang/ClassLoader.h> +#include <java/lang/Integer.h> +#include <java/lang/String.h> +#include <java/lang/StringBuffer.h> +#include <java/lang/Thread.h> +#include <java/nio/ByteBuffer.h> +#include <java/util/ArrayList.h> +#include <java/util/Hashtable.h> +#include <java/util/Iterator.h> + +#include <gnu/classpath/jdwp/VMFrame.h> +#include <gnu/classpath/jdwp/VMMethod.h> +#include <gnu/classpath/jdwp/VMVirtualMachine.h> +#include <gnu/classpath/jdwp/event/EventRequest.h> +#include <gnu/classpath/jdwp/exception/JdwpInternalErrorException.h> +#include <gnu/classpath/jdwp/util/MethodResult.h> + +using namespace java::lang; +using namespace gnu::classpath::jdwp::event; +using namespace gnu::classpath::jdwp::util; + +// JVMTI environment +static jvmtiEnv *_jdwp_jvmtiEnv; + +void +gnu::classpath::jdwp::VMVirtualMachine::initialize () +{ + _jdwp_suspend_counts = new ::java::util::Hashtable (); + JavaVM *vm = _Jv_GetJavaVM (); + vm->GetEnv (reinterpret_cast<void **> (&_jdwp_jvmtiEnv), JVMTI_VERSION_1_0); +} + +void +gnu::classpath::jdwp::VMVirtualMachine ::suspendThread (Thread *thread) +{ + jint value; + Integer *count; + { + JvSynchronize dummy (_jdwp_suspend_counts); + count = reinterpret_cast<Integer *> (_jdwp_suspend_counts->get (thread)); + if (count == NULL) + { + // New -- suspend thread + value = 0; + } + else + { + // Thread already suspended + value = count->intValue (); + } + + count = Integer::valueOf (++value); + _jdwp_suspend_counts->put (thread, count); + } + + if (value == 1) + { + // Suspend the thread + jvmtiError err = _jdwp_jvmtiEnv->SuspendThread (thread); + if (err != JVMTI_ERROR_NONE) + { + using namespace gnu::classpath::jdwp::exception; + char *reason; + _jdwp_jvmtiEnv->GetErrorName (err, &reason); + ::java::lang::String *txt + = JvNewStringLatin1 ("could not suspend thread: "); + ::java::lang::StringBuffer *msg + = new ::java::lang::StringBuffer (txt); + msg->append (JvNewStringLatin1 (reason)); + _jdwp_jvmtiEnv->Deallocate ((unsigned char *) reason); + throw new JdwpInternalErrorException (msg->toString ()); + } + } +} + +void +gnu::classpath::jdwp::VMVirtualMachine::resumeThread (Thread *thread) +{ + jint value; + { + JvSynchronize dummy (_jdwp_suspend_counts); + Integer *count + = reinterpret_cast<Integer *> (_jdwp_suspend_counts->get (thread)); + if (count == NULL) + { + // Thread not suspended: ThreadReference.Resume says to ignore it. + return; + } + else + { + // Decrement suspend count + value = count->intValue () - 1; + } + + if (value == 0) + { + // Thread will be resumed, remove from table + _jdwp_suspend_counts->remove (thread); + } + else + { + // Thread stays suspended: record new suspend count + count = Integer::valueOf (value); + _jdwp_suspend_counts->put (thread, count); + } + } + + if (value == 0) + { + jvmtiError err = _jdwp_jvmtiEnv->ResumeThread (thread); + if (err != JVMTI_ERROR_NONE) + { + using namespace gnu::classpath::jdwp::exception; + char *reason; + _jdwp_jvmtiEnv->GetErrorName (err, &reason); + ::java::lang::String *txt + = JvNewStringLatin1 ("could not resume thread: "); + ::java::lang::StringBuffer *msg + = new ::java::lang::StringBuffer (txt); + msg->append (JvNewStringLatin1 (reason)); + _jdwp_jvmtiEnv->Deallocate ((unsigned char *) reason); + throw new JdwpInternalErrorException (msg->toString ()); + } + } +} + +jint +gnu::classpath::jdwp::VMVirtualMachine::getSuspendCount (Thread *thread) +{ + jint suspensions = 0; + Integer *count + = reinterpret_cast<Integer *> (_jdwp_suspend_counts->get (thread)); + if (count != NULL) + suspensions = count->intValue (); + return suspensions; +} + +void +gnu::classpath::jdwp::VMVirtualMachine::registerEvent (EventRequest *request) +{ + switch (request->getEventKind ()) + { + case EventRequest::EVENT_SINGLE_STEP: + break; + + case EventRequest::EVENT_BREAKPOINT: + break; + + case EventRequest::EVENT_FRAME_POP: + break; + + case EventRequest::EVENT_EXCEPTION: + break; + + case EventRequest::EVENT_USER_DEFINED: + break; + + case EventRequest::EVENT_THREAD_START: + break; + + case EventRequest::EVENT_THREAD_END: + break; + + case EventRequest::EVENT_CLASS_PREPARE: + break; + + case EventRequest::EVENT_CLASS_LOAD: + break; + + case EventRequest::EVENT_CLASS_UNLOAD: + break; + + case EventRequest::EVENT_FIELD_ACCESS: + break; + + case EventRequest::EVENT_FIELD_MODIFY: + break; + + case EventRequest::EVENT_METHOD_ENTRY: + break; + + case EventRequest::EVENT_METHOD_EXIT: + break; + + case EventRequest::EVENT_VM_INIT: + break; + + case EventRequest::EVENT_VM_DEATH: + break; + } +} + +void +gnu::classpath::jdwp::VMVirtualMachine::unregisterEvent (EventRequest *request) +{ + switch (request->getEventKind ()) + { + case EventRequest::EVENT_SINGLE_STEP: + break; + + case EventRequest::EVENT_BREAKPOINT: + break; + + case EventRequest::EVENT_FRAME_POP: + break; + + case EventRequest::EVENT_EXCEPTION: + break; + + case EventRequest::EVENT_USER_DEFINED: + break; + + case EventRequest::EVENT_THREAD_START: + break; + + case EventRequest::EVENT_THREAD_END: + break; + + case EventRequest::EVENT_CLASS_PREPARE: + break; + + case EventRequest::EVENT_CLASS_LOAD: + break; + + case EventRequest::EVENT_CLASS_UNLOAD: + break; + + case EventRequest::EVENT_FIELD_ACCESS: + break; + + case EventRequest::EVENT_FIELD_MODIFY: + break; + + case EventRequest::EVENT_METHOD_ENTRY: + break; + + case EventRequest::EVENT_METHOD_EXIT: + break; + + case EventRequest::EVENT_VM_INIT: + break; + + case EventRequest::EVENT_VM_DEATH: + break; + } +} + +void +gnu::classpath::jdwp::VMVirtualMachine::clearEvents (jbyte kind) +{ +} + +jint +gnu::classpath::jdwp::VMVirtualMachine::getAllLoadedClassesCount (void) +{ + return 0; +} + +java::util::Iterator * +gnu::classpath::jdwp::VMVirtualMachine::getAllLoadedClasses (void) +{ + return NULL; +} + +jint +gnu::classpath::jdwp::VMVirtualMachine::getClassStatus (jclass klass) +{ + return 0; +} + +JArray<gnu::classpath::jdwp::VMMethod *> * +gnu::classpath::jdwp::VMVirtualMachine::getAllClassMethods (jclass klass) +{ + return NULL; +} + +gnu::classpath::jdwp::VMMethod * +gnu::classpath::jdwp::VMVirtualMachine::getClassMethod (jclass klass, jlong id) +{ + return NULL; +} + +java::util::ArrayList * +gnu::classpath::jdwp::VMVirtualMachine::getFrames (Thread *thread, + jint start, + jint length) +{ + return NULL; +} + +gnu::classpath::jdwp::VMFrame * +gnu::classpath::jdwp::VMVirtualMachine::getFrame (Thread *thread, + ::java::nio::ByteBuffer *bb) +{ + return NULL; +} + +jint +gnu::classpath::jdwp::VMVirtualMachine::getFrameCount (Thread *thread) +{ + return 0; +} + +jint +gnu::classpath::jdwp::VMVirtualMachine::getThreadStatus (Thread *thread) +{ + return 0; +} + +java::util::ArrayList * +gnu::classpath::jdwp::VMVirtualMachine::getLoadRequests (ClassLoader *cl) +{ + return NULL; +} + +MethodResult * +gnu::classpath::jdwp::VMVirtualMachine::executeMethod (jobject obj, + Thread *thread, + jclass clazz, + reflect::Method *method, + jobjectArray values, + jboolean nonVirtual) +{ + return NULL; +} + +jstring +gnu::classpath::jdwp::VMVirtualMachine::getSourceFile (jclass clazz) +{ + return NULL; +} diff --git a/gcc-4.2.1/libjava/gnu/classpath/natSystemProperties.cc b/gcc-4.2.1/libjava/gnu/classpath/natSystemProperties.cc new file mode 100644 index 000000000..8196ea33f --- /dev/null +++ b/gcc-4.2.1/libjava/gnu/classpath/natSystemProperties.cc @@ -0,0 +1,422 @@ +// natSystemProperties.cc - Implementation of native side of +// SystemProperties class. + +/* 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. */ + +#include <config.h> +#include <platform.h> + +#include <stdlib.h> +#include <errno.h> + +#ifdef HAVE_PWD_H +#include <pwd.h> +#endif + +#ifdef HAVE_UNAME +#include <sys/utsname.h> +#endif + +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif + +#ifdef HAVE_LANGINFO_H +#include <langinfo.h> +#endif + +#include <gcj/cni.h> +#include <jvm.h> +#include <java-props.h> +#include <gnu/classpath/SystemProperties.h> +#include <java/lang/String.h> +#include <jni.h> + +char *_Jv_Module_Load_Path = NULL; + +#ifdef USE_LTDL +#include <ltdl.h> + +void +_Jv_SetDLLSearchPath (const char *path) +{ + _Jv_Module_Load_Path = strdup (path); +} + +#else + +void +_Jv_SetDLLSearchPath (const char *) +{ + // Nothing. +} + +#endif /* USE_LTDL */ + +#if ! defined (DEFAULT_FILE_ENCODING) && defined (HAVE_ICONV) \ + && defined (HAVE_NL_LANGINFO) + +static const char * +file_encoding () +{ + setlocale (LC_CTYPE, ""); + const char *e = nl_langinfo (CODESET); + if (e == NULL || *e == '\0') + e = "8859_1"; + return e; +} + +#define DEFAULT_FILE_ENCODING file_encoding () + +#endif + +#ifndef DEFAULT_FILE_ENCODING +#define DEFAULT_FILE_ENCODING "8859_1" +#endif + +static const char *default_file_encoding = DEFAULT_FILE_ENCODING; + +#if defined(HAVE_GETPWUID_R) && defined(_POSIX_PTHREAD_SEMANTICS) +/* Use overload resolution to find out the signature of getpwuid_r. */ + + /* This is Posix getpwuid_r. */ +template <typename T_uid, typename T_passwd, typename T_buf, typename T_len> +static inline int +getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r, + T_buf *buf_r, T_len len_r, + T_passwd **pwd_entry_ptr), + uid_t user_id, struct passwd *pwd_r, + char *buf_r, size_t len_r, struct passwd **pwd_entry) +{ + return getpwuid_r (user_id, pwd_r, buf_r, len_r, pwd_entry); +} + +/* This is used on HPUX 10.20 */ +template <typename T_uid, typename T_passwd, typename T_buf, typename T_len> +static inline int +getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r, + T_buf *buf_r, T_len len_r), + uid_t user_id, struct passwd *pwd_r, + char *buf_r, size_t len_r, struct passwd **pwd_entry) +{ + return getpwuid_r (user_id, pwd_r, buf_r, len_r); +} + +/* This is used on IRIX 5.2. */ +template <typename T_uid, typename T_passwd, typename T_buf, typename T_len> +static inline int +getpwuid_adaptor(T_passwd * (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r, + T_buf *buf_r, T_len len_r), + uid_t user_id, struct passwd *pwd_r, + char *buf_r, size_t len_r, struct passwd **pwd_entry) +{ + *pwd_entry = getpwuid_r (user_id, pwd_r, buf_r, len_r); + return (*pwd_entry == NULL) ? errno : 0; +} +#endif + +// Prepend GCJ_VERSIONED_LIBDIR to a module search path stored in a +// Java string, if the path is not already prefixed by +// GCJ_VERSIONED_LIBDIR. Return a newly JvMalloc'd char buffer. The +// result should be freed using JvFree. See +// _Jv_PrependVersionedLibdir in prims.cc. +static char* +PrependVersionedLibdir (::java::lang::String* libpath) +{ + char* retval = 0; + + // Extract a C char array from libpath. + char* val = (char*) _Jv_Malloc (JvGetStringUTFLength (libpath) + 1); + jsize total = JvGetStringUTFRegion (libpath, 0, libpath->length(), val); + val[total] = '\0'; + retval = _Jv_PrependVersionedLibdir (val); + JvFree (val); + + return retval; +} + +void +gnu::classpath::SystemProperties::insertSystemProperties (java::util::Properties *newprops) +{ + // A convenience define. +#define SET(Prop,Val) \ + newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val)) + + // A mixture of the Java Product Versioning Specification + // (introduced in 1.2), and earlier versioning properties. Some + // programs rely on seeing values that they expect, so we claim to + // be a 1.4-ish VM for their sake. + SET ("java.version", JV_VERSION); + SET ("java.runtime.version", JV_VERSION); + SET ("java.vendor", "Free Software Foundation, Inc."); + SET ("java.vendor.url", "http://gcc.gnu.org/java/"); + SET ("java.class.version", "48.0"); + SET ("java.vm.specification.version", "1.0"); + SET ("java.vm.specification.name", "Java(tm) Virtual Machine Specification"); + SET ("java.vm.specification.vendor", "Sun Microsystems Inc."); + SET ("java.vm.version", __VERSION__); + SET ("java.vm.vendor", "Free Software Foundation, Inc."); + SET ("java.vm.name", "GNU libgcj"); + SET ("java.specification.version", JV_API_VERSION); + SET ("java.specification.name", "Java(tm) Platform API Specification"); + SET ("java.specification.vendor", "Sun Microsystems Inc."); + + char value[100]; +#define NAME "GNU libgcj " + strcpy (value, NAME); + strncpy (value + sizeof (NAME) - 1, __VERSION__, + sizeof(value) - sizeof(NAME)); + value[sizeof (value) - 1] = '\0'; + jstring version = JvNewStringLatin1 (value); + newprops->put (JvNewStringLatin1 ("java.fullversion"), version); + newprops->put (JvNewStringLatin1 ("java.vm.info"), version); + + // This definition is rather arbitrary: we choose $(prefix). In + // part we do this because most people specify only --prefix and + // nothing else when installing gcj. Plus, people are free to + // redefine `java.home' with `-D' if necessary. + SET ("java.home", JAVA_HOME); + SET ("gnu.classpath.home", PREFIX); + // This is set to $(toolexeclibdir) because we use this to find + // .security files at runtime. + char val2[sizeof ("file://") + sizeof (TOOLEXECLIBDIR) + 1]; + strcpy (val2, "file://"); + strcat (val2, TOOLEXECLIBDIR); + SET ("gnu.classpath.home.url", val2); + + SET ("file.encoding", default_file_encoding); + +#ifdef HAVE_UNAME + struct utsname u; + if (! uname (&u)) + { + SET ("os.name", u.sysname); + SET ("os.version", u.release); + + // Normalize x86 architecture names to "i386" (except on Windows, which + // is handled in win32.cc). + if (u.machine[0] == 'i' + && u.machine[1] != 0 + && u.machine[2] == '8' + && u.machine[3] == '6' + && u.machine[4] == 0) + SET ("os.arch", "i386"); + else + SET ("os.arch", u.machine); + } + else + { + SET ("os.name", "unknown"); + SET ("os.arch", "unknown"); + SET ("os.version", "unknown"); + } +#endif /* HAVE_UNAME */ + +#ifndef NO_GETUID +#ifdef HAVE_PWD_H + uid_t user_id = getuid (); + struct passwd *pwd_entry; + +#if defined(HAVE_GETPWUID_R) && defined(_POSIX_PTHREAD_SEMANTICS) + struct passwd pwd_r; + size_t len_r = 200; + char *buf_r = (char *) _Jv_AllocBytes (len_r); + + while (buf_r != NULL) + { + int r = getpwuid_adaptor (getpwuid_r, user_id, &pwd_r, + buf_r, len_r, &pwd_entry); + if (r == 0) + break; + else if (r != ERANGE) + { + pwd_entry = NULL; + break; + } + len_r *= 2; + buf_r = (char *) _Jv_AllocBytes (len_r); + } +#else + pwd_entry = getpwuid (user_id); +#endif /* HAVE_GETPWUID_R */ + + if (pwd_entry != NULL) + { + SET ("user.name", pwd_entry->pw_name); + SET ("user.home", pwd_entry->pw_dir); + SET ("gnu.gcj.user.realname", pwd_entry->pw_gecos); + } +#endif /* HAVE_PWD_H */ +#endif /* NO_GETUID */ + +#ifdef HAVE_GETCWD +#ifdef HAVE_UNISTD_H + /* Use getcwd to set "user.dir". */ + int buflen = 250; + char *buffer = (char *) malloc (buflen); + while (buffer != NULL) + { + if (getcwd (buffer, buflen) != NULL) + { + SET ("user.dir", buffer); + break; + } + if (errno != ERANGE) + break; + buflen = 2 * buflen; + buffer = (char *) realloc (buffer, buflen); + } + if (buffer != NULL) + free (buffer); +#endif /* HAVE_UNISTD_H */ +#endif /* HAVE_GETCWD */ + + // Set user locale properties based on setlocale() +#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) + // We let the user choose the locale. However, since Java differs + // from POSIX, we arbitrarily pick LC_MESSAGES as determining the + // Java locale. We can't use LC_ALL because it might return a full + // list of all the settings. If we don't have LC_MESSAGES then we + // just default to `en_US'. + setlocale (LC_ALL, ""); + char *locale = setlocale (LC_MESSAGES, ""); + if (locale && strlen (locale) >= 2) + { + char buf[3]; + buf[2] = '\0'; + // copy the first two chars to user.language + strncpy (buf, locale, 2); + SET ("user.language", buf); + // if the next char is a '_', copy the two after that to user.region + locale += 2; + if (locale[0] == '_') + { + locale++; + strncpy (buf, locale, 2); + SET ("user.region", buf); + } + } + else +#endif /* HAVE_SETLOCALE and HAVE_LC_MESSAGES */ + { + SET ("user.language", "en"); + SET ("user.region", "US"); + } + + // Set the java extension directories property if it has not yet been + // specified. + ::java::lang::String *extdirs = newprops->getProperty(JvNewStringLatin1("java.ext.dirs")); + if (! extdirs) + SET ("java.ext.dirs", JAVA_EXT_DIRS); + + // The endorsed directories that libgcj knows about by default. + // This is a way to get other jars into the boot class loader + // without overriding java.endorsed.dirs. + SET ("gnu.gcj.runtime.endorsed.dirs", GCJ_ENDORSED_DIRS); + + // The path to libgcj's boot classes + SET ("sun.boot.class.path", BOOT_CLASS_PATH); + + // If there is a default system database, set it. + SET ("gnu.gcj.precompiled.db.path", LIBGCJ_DEFAULT_DATABASE); + + // Set some properties according to whatever was compiled in with + // `-D'. Important: after this point, the only properties that + // should be set are those which either the user cannot meaningfully + // override, or which augment whatever value the user has provided. + for (int i = 0; i < _Jv_Properties_Count; ++i) + { + const char *s, *p; + // Find the `='. + for (s = p = _Jv_Compiler_Properties[i]; *s && *s != '='; ++s) + ; + jstring name = JvNewStringLatin1 (p, s - p); + jstring val = JvNewStringLatin1 (*s == '=' ? s + 1 : s); + newprops->put (name, val); + } + + // Set the system properties from the user's environment. +#ifndef DISABLE_GETENV_PROPERTIES + if (_Jv_Environment_Properties) + { + size_t i = 0; + + while (_Jv_Environment_Properties[i].key) + { + SET (_Jv_Environment_Properties[i].key, + _Jv_Environment_Properties[i].value); + i++; + } + } +#endif + + // The name used to invoke this process (argv[0] in C). + SET ("gnu.gcj.progname", _Jv_GetSafeArg (0)); + + // Allow platform specific settings and overrides. + _Jv_platform_initProperties (newprops); + + // If java.library.path is set, tell libltdl so we search the new + // directories as well. + ::java::lang::String *path = newprops->getProperty(JvNewStringLatin1("java.library.path")); + if (path) + { + // Prepend GCJ_VERSIONED_LIBDIR to the module load path so that + // libgcj will find its own JNI libraries, like libgtkpeer.so. + char* val = PrependVersionedLibdir (path); + _Jv_SetDLLSearchPath (val); + _Jv_Free (val); + } + else + { + // Set a value for user code to see. +#ifdef USE_LTDL + char *libpath = getenv (LTDL_SHLIBPATH_VAR); + char* val = _Jv_PrependVersionedLibdir (libpath); + SET ("java.library.path", val); + _Jv_SetDLLSearchPath (val); + _Jv_Free (val); +#else + SET ("java.library.path", ""); +#endif + } + + // If java.class.path is still not set then set it according to the + // CLASSPATH environment variable if given. See gij.cc main () and + // prims.cc _Jv_CreateJavaVM () for all the ways this could have + // been set much earlier. + // If CLASSPATH isn't set or if the path is empty fall back to "." + path = newprops->getProperty(JvNewStringLatin1("java.class.path")); + if (!path) + { + char *classpath = getenv("CLASSPATH"); + if (classpath && classpath[0] != 0) + { + path = JvNewStringLatin1 (classpath); + newprops->put(JvNewStringLatin1 ("java.class.path"), path); + } + } + + if (!path || path->length() == 0) + SET ("java.class.path", "."); +} + +jboolean +gnu::classpath::SystemProperties::isWordsBigEndian (void) +{ + union + { + long lval; + char cval; + } u; + + u.lval = 1; + return u.cval == 0; +} + |
