OSDN Git Service

auto import from //branches/cupcake/...@126645
authorThe Android Open Source Project <initial-contribution@android.com>
Fri, 16 Jan 2009 00:12:07 +0000 (16:12 -0800)
committerThe Android Open Source Project <initial-contribution@android.com>
Fri, 16 Jan 2009 00:12:07 +0000 (16:12 -0800)
17 files changed:
hit/src/com/android/hit/ArrayInstance.java
hit/src/com/android/hit/ClassInstance.java
hit/src/com/android/hit/Instance.java
hit/src/com/android/hit/Queries.java
libcore/Android.mk
libcore/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java
libcore/luni-kernel/src/main/java/java/lang/Class.java
libcore/luni-kernel/src/main/java/java/lang/reflect/Constructor.java
libcore/luni-kernel/src/main/java/java/lang/reflect/Field.java
libcore/luni-kernel/src/main/java/java/lang/reflect/Method.java
libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java
libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java
libcore/nio/src/main/java/java/nio/Buffer.java
libcore/nio/src/main/java/java/nio/IntToByteBufferAdapter.java
libcore/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java
libcore/xml/src/main/java/org/xml/sax/ext/Attributes2Impl.java
libcore/xml/src/test/java/tests/api/org/xml/sax/ext/Attributes2ImplTest.java

index ab07714..cdb5616 100644 (file)
@@ -134,4 +134,55 @@ public class ArrayInstance extends Instance {
     public final String toString() {
         return String.format("%s@0x08x", getTypeName(), mId);
     }
+
+    @Override
+    public String describeReferenceTo(long referent) {
+        //  If this isn't an object array then we can't refer to an object
+        if (mType != Types.OBJECT) {
+            return super.describeReferenceTo(referent);
+        }
+        
+        int idSize = Types.getTypeSize(mType);
+        final int N = mNumEntries;
+        int numRefs = 0;
+        StringBuilder result = new StringBuilder("Elements [");
+        ByteArrayInputStream bais = new ByteArrayInputStream(mData);
+        DataInputStream dis = new DataInputStream(bais);
+        
+        /*
+         * Spin through all the objects and build up a string describing
+         * all of the array elements that refer to the target object.
+         */
+        for (int i = 0; i < N; i++) {
+            long id;
+            
+            try {
+                if (idSize == 4) {
+                    id = dis.readInt();
+                } else {
+                    id = dis.readLong();
+                }
+                
+                if (id == referent) {
+                    numRefs++;
+                    
+                    if (numRefs > 1) {
+                        result.append(", ");
+                    }
+                    
+                    result.append(i);
+                }
+            } catch (java.io.IOException e) {
+                e.printStackTrace();
+            }
+        }
+        
+        if (numRefs == 0) {
+            return super.describeReferenceTo(referent);
+        }
+
+        result.append("]");
+        
+        return result.toString();
+    }
 }
index a902949..36525be 100644 (file)
@@ -152,4 +152,57 @@ public class ClassInstance extends Instance {
     public final String toString() {
         return String.format("%s@0x%08x", getTypeName(), mId);
     }
+
+    @Override
+    public String describeReferenceTo(long referent) {
+        ClassObj isa = mHeap.mState.findClass(mClassId);
+        int[] types = isa.mFieldTypes;
+        String[] fieldNames = isa.mFieldNames;
+        ByteArrayInputStream bais = new ByteArrayInputStream(mFieldValues);
+        DataInputStream dis = new DataInputStream(bais);
+        final int N = types.length;
+        StringBuilder result = new StringBuilder("Referenced in field(s):");
+        int numReferences = 0;
+        
+        /*
+         * Spin through the list of fields, add info about the field
+         * references to the output text.
+         */
+        try {
+            for (int i = 0; i < N; i++) {
+                int type = types[i];
+                int size = Types.getTypeSize(type);
+                
+                if (type == Types.OBJECT) {
+                    long id;
+                    
+                    if (size == 4) {
+                        id = dis.readInt();
+                    } else {
+                        id = dis.readLong();
+                    }
+                    
+                    if (id == referent) {
+                        numReferences++;
+                        result.append("\n    ");
+                        result.append(fieldNames[i]);
+                    }
+                } else {
+                    dis.skipBytes(size);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        /*
+         *  TODO:  perform a similar loop over the static fields of isa
+         */
+
+        if (numReferences == 0) {
+            return super.describeReferenceTo(referent);
+        }
+        
+        return result.toString();
+    }
 }
index e06a427..24db38d 100644 (file)
@@ -106,4 +106,12 @@ public abstract class Instance {
         
         return mParents;
     }
+
+    /*
+     * If this object has a reference to the object identified by id, return
+     * a String describing the reference in detail.
+     */
+    public String describeReferenceTo(long id) {
+        return "No reference to 0x" + Long.toHexString(id); 
+    }
 }
index c0a40d5..cc692b0 100644 (file)
@@ -26,6 +26,36 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 
 public class Queries {
+    /*
+     * NOTES:  Here's a list of the queries that can be done in hat and 
+     * how you'd perform a similar query here in hit:
+     *
+     * hat                      hit
+     * ------------------------------------------------------------------------
+     * allClasses               classes
+     * allClassesWithPlatform   allClasses
+     * class                    findClass
+     * instances                instancesOf
+     * allInstances             allInstancesOf
+     * object                   findObject
+     * showRoots                getRoots
+     * newInstances             newInstances
+     *
+     * reachableFrom            make a call to findObject to get the target
+     *                          parent object, this will give you an Instance.
+     *                          Then call visit(Set, Filter) on that to have
+     *                          it build the set of objects in its subgraph.
+     *
+     * rootsTo                  make a call to findObject on the leaf node
+     *                          in question, this will give you an Instance.
+     *                          Instances have an ArrayList of all of the
+     *                          parent objects that refer to it.  You can
+     *                          follow those parent links until you hit an
+     *                          object whose parent is null or a ThreadObj.
+     *                          You've not successfully traced the paths to
+     *                          the roots.
+     */
+
     private static final String DEFAULT_PACKAGE = "<default>";
 
     /*
index cf369a7..c12ce9a 100644 (file)
@@ -22,6 +22,9 @@ LOCAL_JAVA_RESOURCE_DIRS := $(call all-core-resource-dirs,main)
 LOCAL_NO_STANDARD_LIBRARIES := true
 LOCAL_DX_FLAGS := --core-library
 
+LOCAL_NO_EMMA_INSTRUMENT := true
+LOCAL_NO_EMMA_COMPILE := true
+
 LOCAL_MODULE := core
 
 include $(BUILD_JAVA_LIBRARY)
index e33e1b2..3b9bf86 100644 (file)
@@ -17,7 +17,7 @@ package com.ibm.icu4jni.charset;
 import com.ibm.icu4jni.common.ErrorCode;
 // BEGIN android-removed
 // import com.ibm.icu4jni.converters.NativeConverter;
-// ENd android-removed
+// END android-removed
 
 
 import java.nio.CharBuffer;
@@ -253,9 +253,9 @@ public final class CharsetDecoderICU extends CharsetDecoder{
             if(ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR){
                 return CoderResult.OVERFLOW;
             }else if(ec==ErrorCode.U_INVALID_CHAR_FOUND){
-                return CoderResult.unmappableForLength(data[INVALID_BYTES]);
+                return CoderResult.malformedForLength(data[INVALID_BYTES]);
             }else if(ec==ErrorCode.U_ILLEGAL_CHAR_FOUND){
-                return CoderResult.unmappableForLength(data[INVALID_BYTES]);
+                return CoderResult.malformedForLength(data[INVALID_BYTES]);
             }
             /* decoding action succeded */
             return CoderResult.UNDERFLOW;
index c65ded9..dc5f1e1 100644 (file)
@@ -927,7 +927,8 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
      * @since Android 1.0
      */
     public Type[] getGenericInterfaces() {
-        GenericSignatureParser parser = new GenericSignatureParser();
+        GenericSignatureParser parser = new GenericSignatureParser(
+                VMStack.getCallingClassLoader2());
         parser.parseForClass(this, getSignatureAttribute());
         return Types.getClonedTypeArray(parser.interfaceTypes);
     }
@@ -940,7 +941,8 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
      * @since Android 1.0
      */
     public Type getGenericSuperclass() {
-        GenericSignatureParser parser = new GenericSignatureParser();
+        GenericSignatureParser parser = new GenericSignatureParser(
+                VMStack.getCallingClassLoader2());
         parser.parseForClass(this, getSignatureAttribute());
         return Types.getType(parser.superclassType);
     }
@@ -1276,7 +1278,8 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
      */
     @SuppressWarnings("unchecked")
     public synchronized TypeVariable<Class<T>>[] getTypeParameters() {
-        GenericSignatureParser parser = new GenericSignatureParser();
+        GenericSignatureParser parser = new GenericSignatureParser(
+                VMStack.getCallingClassLoader2());
         parser.parseForClass(this, getSignatureAttribute());
         return parser.formalTypeParameters.clone();
     }
index b02dcae..54fac6a 100644 (file)
@@ -32,6 +32,8 @@
 
 package java.lang.reflect;
 
+import dalvik.system.VMStack;
+
 import java.lang.annotation.Annotation;
 
 import org.apache.harmony.kernel.vm.StringUtils;
@@ -64,7 +66,8 @@ public final class Constructor<T> extends AccessibleObject implements GenericDec
     private synchronized void initGenericTypes() {
         if (!genericTypesAreInitialized) {
             String signatureAttribute = getSignatureAttribute();
-            GenericSignatureParser parser = new GenericSignatureParser();
+            GenericSignatureParser parser = new GenericSignatureParser(
+                    VMStack.getCallingClassLoader2());
             parser.parseForConstructor(this, signatureAttribute);
             formalTypeParameters = parser.formalTypeParameters;
             genericParameterTypes = parser.parameterTypes;
index 27cf34a..a6c930b 100644 (file)
@@ -32,6 +32,8 @@
 
 package java.lang.reflect;
 
+import dalvik.system.VMStack;
+
 import java.lang.annotation.Annotation;
 
 import org.apache.harmony.luni.lang.reflect.GenericSignatureParser;
@@ -98,7 +100,8 @@ public final class Field extends AccessibleObject implements Member {
     private synchronized void initGenericType() {
         if (!genericTypesAreInitialized) {
             String signatureAttribute = getSignatureAttribute();
-            GenericSignatureParser parser = new GenericSignatureParser();
+            GenericSignatureParser parser = new GenericSignatureParser(
+                    VMStack.getCallingClassLoader2());
             parser.parseForField(this.declaringClass, signatureAttribute);
             genericType = parser.fieldType;
             if (genericType == null) {
index 7fc0322..473726d 100644 (file)
@@ -32,6 +32,8 @@
 
 package java.lang.reflect;
 
+import dalvik.system.VMStack;
+
 import java.lang.annotation.Annotation;
 
 import org.apache.harmony.kernel.vm.StringUtils;
@@ -68,7 +70,8 @@ public final class Method extends AccessibleObject implements GenericDeclaration
     private synchronized void initGenericTypes() {
         if (!genericTypesAreInitialized) {
             String signatureAttribute = getSignatureAttribute();
-            GenericSignatureParser parser = new GenericSignatureParser();
+            GenericSignatureParser parser = new GenericSignatureParser(
+                    VMStack.getCallingClassLoader2());
             parser.parseForMethod(this, signatureAttribute);
             formalTypeParameters = parser.formalTypeParameters;
             genericParameterTypes = parser.parameterTypes;
index 83505e1..2ea0b5a 100644 (file)
@@ -73,6 +73,7 @@ public class GenericSignatureParser {
     public Type fieldType;
     public ListOfTypes interfaceTypes;
     public Type superclassType;
+    public ClassLoader loader;
     
     GenericDeclaration genericDecl;
 
@@ -93,6 +94,10 @@ public class GenericSignatureParser {
     char[] buffer;
     int pos;
 
+    public GenericSignatureParser(ClassLoader loader) {
+        this.loader = loader;
+    }
+
     void setInput(GenericDeclaration genericDecl, String input) {
         if (input != null) {
             this.genericDecl = genericDecl;
@@ -297,7 +302,7 @@ public class GenericSignatureParser {
 
         ListOfTypes typeArgs = parseOptTypeArguments();
         ImplForType parentType = 
-                new ImplForType(null, qualIdent.toString(), typeArgs);
+                new ImplForType(null, qualIdent.toString(), typeArgs, loader);
         ImplForType type = parentType;
 
         while (symbol == '.') {
@@ -306,7 +311,8 @@ public class GenericSignatureParser {
             scanIdentifier();
             qualIdent.append("$").append(identifier); // FIXME: is "$" correct?
             typeArgs = parseOptTypeArguments();
-            type = new ImplForType(parentType, qualIdent.toString(), typeArgs);
+            type = new ImplForType(parentType, qualIdent.toString(), typeArgs, 
+                    loader);
         }
 
         expect(';');
index 8553276..70f05b4 100644 (file)
@@ -25,13 +25,15 @@ public final class ImplForType implements ParameterizedType {
     private Type ownerTypeRes;
     private Class rawType; // Already resolved.
     private final String rawTypeName;
+    private ClassLoader loader;
 
 
     public ImplForType(ImplForType ownerType, String rawTypeName, 
-            ListOfTypes args) {
+            ListOfTypes args, ClassLoader loader) {
         this.ownerType0 = ownerType;
         this.rawTypeName = rawTypeName;
         this.args = args;
+        this.loader = loader;
     }
 
 
@@ -53,12 +55,11 @@ public final class ImplForType implements ParameterizedType {
 
     public Class getRawType() {
         if (rawType == null) {
-        // TODO which ClassLoader to use?
-        // Here the actual loading of the class has to be performed and the 
-        // Exceptions have to be re-thrown TypeNotPresent...
-        // How to deal with member (nested) classes?
+            // Here the actual loading of the class has to be performed and the 
+            // Exceptions have to be re-thrown TypeNotPresent...
+            // How to deal with member (nested) classes?
             try {
-                rawType = Class.forName(rawTypeName);
+                rawType = Class.forName(rawTypeName, false, loader);
             } catch (ClassNotFoundException e) {
                 throw new TypeNotPresentException(rawTypeName, e);
             }
index 844d2ce..9e870e4 100644 (file)
@@ -150,21 +150,11 @@ public abstract class Buffer {
      * @since Android 1.0
      */
     public final Buffer clear() {
-        // BEGIN android-changed
-        internalClear();
-        // END android-changed
-        return this;
-    }
-
-    // BEGIN android-added
-    // We need a possibility to change the behavior of clear in some optimized
-    // DirectByteBuffer adapters.
-    void internalClear() {
         position = 0;
         mark = UNSET_MARK;
         limit = capacity;
+        return this;
     }
-    // END android-added
 
     /**
      * Flips this buffer.
index e52f6b6..91b9311 100644 (file)
@@ -194,8 +194,11 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
     }
 
     // BEGIN android-added
+    @Override
     public IntBuffer put(int[] i, int off, int len) {
         if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
+            byteBuffer.limit(limit << 2);
+            byteBuffer.position(position << 2);
             ((ReadWriteDirectByteBuffer) byteBuffer).put(i, off, len);
             this.position += len;
             return this;
@@ -203,14 +206,6 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
             return super.put(i, off, len);
         }
     }
-    
-    @Override
-    void internalClear() {
-        if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
-            byteBuffer.clear();
-        }
-        super.internalClear();
-    }
     // END android-added
 
     public IntBuffer slice() {
index fe4fff4..41ce50c 100644 (file)
@@ -194,8 +194,11 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements DirectBuffer
     }
     
     // BEGIN android-added
+    @Override
     public ShortBuffer put(short[] s, int off, int len) {
         if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
+            byteBuffer.limit(limit << 1);
+            byteBuffer.position(position << 1);
             ((ReadWriteDirectByteBuffer) byteBuffer).put(s, off, len);
             this.position += len;
             return this;
@@ -203,14 +206,6 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements DirectBuffer
             return super.put(s, off, len);
         }
     }
-    
-    @Override
-    void internalClear() {
-        if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
-            byteBuffer.clear();
-        }
-        super.internalClear();
-    }
     // END android-added
 
     public ShortBuffer slice() {
index 81b9b93..fc36805 100644 (file)
@@ -44,7 +44,12 @@ public class Attributes2Impl extends AttributesImpl implements Attributes2
     /**
      * Construct a new, empty Attributes2Impl object.
      */
-    public Attributes2Impl () { }
+    public Attributes2Impl () {
+        // BEGIN android-added
+        declared = new boolean[0];
+        specified = new boolean[0];
+        // END android-added
+    }
 
 
     /**
@@ -241,7 +246,9 @@ public class Attributes2Impl extends AttributesImpl implements Attributes2
 
     int length = getLength ();
 
-    if (length < specified.length) {
+    // BEGIN android-changed
+    if (length > specified.length) {
+    // END android-changed
         boolean    newFlags [];
 
         newFlags = new boolean [length];
index cd1b872..9ccdc8a 100644 (file)
@@ -72,7 +72,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "setAttributes",
         args = { Attributes.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testSetAttributes() {
         // Ordinary case with Attributes2Impl
         Attributes2Impl attrs = new Attributes2Impl();
@@ -130,7 +129,6 @@ public class Attributes2ImplTest extends TestCase {
         args = { String.class, String.class, String.class, String.class,
                  String.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testAddAttribute() {
         Attributes2Impl attrs = new Attributes2Impl();
         
@@ -170,7 +168,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "removeAttribute",
         args = { int.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testRemoveAttribute() {
         Attributes2Impl attrs = new Attributes2Impl(multi);
         
@@ -216,7 +213,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "Attributes2Impl",
         args = {  }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testAttributes2Impl() {
         assertEquals(0, empty.getLength());
     }
@@ -226,7 +222,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "Attributes2Impl",
         args = { Attributes.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testAttributes2ImplAttributes() {
         // Ordinary case with Attributes2Impl
         Attributes2Impl attrs = new Attributes2Impl(multi);
@@ -279,7 +274,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "isDeclared",
         args = { int.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testIsDeclaredInt() {
         // Ordinary cases
         assertEquals(false, multi.isDeclared(0));
@@ -306,7 +300,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "isDeclared",
         args = { String.class, String.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testIsDeclaredStringString() {
         // Ordinary cases
         assertEquals(false, multi.isDeclared("http://some.uri", "foo"));
@@ -326,7 +319,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "isDeclared",
         args = { String.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testIsDeclaredString() {
         // Ordinary cases
         assertEquals(false, multi.isDeclared("ns1:foo"));
@@ -346,7 +338,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "isSpecified",
         args = { int.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testIsSpecifiedInt() {
         // Ordinary cases
         assertEquals(false, multi.isSpecified(1));
@@ -373,7 +364,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "isSpecified",
         args = { String.class, String.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testIsSpecifiedStringString() {
         // Ordinary cases
         assertEquals(false, multi.isSpecified("http://some.uri", "bar"));
@@ -393,7 +383,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "isSpecified",
         args = { String.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testIsSpecifiedString() {
         // Ordinary cases
         assertEquals(false, multi.isSpecified("ns1:bar"));
@@ -413,7 +402,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "setDeclared",
         args = { int.class, boolean.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testSetDeclared() {
         // Ordinary cases
         multi.setSpecified(0, false);
@@ -446,7 +434,6 @@ public class Attributes2ImplTest extends TestCase {
         method = "setSpecified",
         args = { int.class, boolean.class }
     )
-    @KnownFailure("SAX2 RI of Attributes2Impl severely broken; needs fixing.")
     public void testSetSpecified() {
         // Ordinary cases
         multi.setSpecified(0, false);