From: The Android Open Source Project Date: Fri, 16 Jan 2009 00:12:07 +0000 (-0800) Subject: auto import from //branches/cupcake/...@126645 X-Git-Tag: android-x86-2.2~1049 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=066bed5fb19102e4f560f242b0cee645f1ed8b31;p=android-x86%2Fdalvik.git auto import from //branches/cupcake/...@126645 --- diff --git a/hit/src/com/android/hit/ArrayInstance.java b/hit/src/com/android/hit/ArrayInstance.java index ab07714a6..cdb56167f 100644 --- a/hit/src/com/android/hit/ArrayInstance.java +++ b/hit/src/com/android/hit/ArrayInstance.java @@ -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(); + } } diff --git a/hit/src/com/android/hit/ClassInstance.java b/hit/src/com/android/hit/ClassInstance.java index a9029491d..36525bef3 100644 --- a/hit/src/com/android/hit/ClassInstance.java +++ b/hit/src/com/android/hit/ClassInstance.java @@ -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(); + } } diff --git a/hit/src/com/android/hit/Instance.java b/hit/src/com/android/hit/Instance.java index e06a4275a..24db38d1b 100644 --- a/hit/src/com/android/hit/Instance.java +++ b/hit/src/com/android/hit/Instance.java @@ -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); + } } diff --git a/hit/src/com/android/hit/Queries.java b/hit/src/com/android/hit/Queries.java index c0a40d57d..cc692b043 100644 --- a/hit/src/com/android/hit/Queries.java +++ b/hit/src/com/android/hit/Queries.java @@ -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 = ""; /* diff --git a/libcore/Android.mk b/libcore/Android.mk index cf369a77a..c12ce9a74 100644 --- a/libcore/Android.mk +++ b/libcore/Android.mk @@ -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) diff --git a/libcore/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/libcore/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java index e33e1b2b0..3b9bf863f 100644 --- a/libcore/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java +++ b/libcore/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java @@ -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; diff --git a/libcore/luni-kernel/src/main/java/java/lang/Class.java b/libcore/luni-kernel/src/main/java/java/lang/Class.java index c65ded992..dc5f1e100 100644 --- a/libcore/luni-kernel/src/main/java/java/lang/Class.java +++ b/libcore/luni-kernel/src/main/java/java/lang/Class.java @@ -927,7 +927,8 @@ public final class Class 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 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 implements Serializable, AnnotatedElement, GenericDe */ @SuppressWarnings("unchecked") public synchronized TypeVariable>[] getTypeParameters() { - GenericSignatureParser parser = new GenericSignatureParser(); + GenericSignatureParser parser = new GenericSignatureParser( + VMStack.getCallingClassLoader2()); parser.parseForClass(this, getSignatureAttribute()); return parser.formalTypeParameters.clone(); } diff --git a/libcore/luni-kernel/src/main/java/java/lang/reflect/Constructor.java b/libcore/luni-kernel/src/main/java/java/lang/reflect/Constructor.java index b02dcae16..54fac6a5a 100644 --- a/libcore/luni-kernel/src/main/java/java/lang/reflect/Constructor.java +++ b/libcore/luni-kernel/src/main/java/java/lang/reflect/Constructor.java @@ -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 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; diff --git a/libcore/luni-kernel/src/main/java/java/lang/reflect/Field.java b/libcore/luni-kernel/src/main/java/java/lang/reflect/Field.java index 27cf34a65..a6c930b0e 100644 --- a/libcore/luni-kernel/src/main/java/java/lang/reflect/Field.java +++ b/libcore/luni-kernel/src/main/java/java/lang/reflect/Field.java @@ -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) { diff --git a/libcore/luni-kernel/src/main/java/java/lang/reflect/Method.java b/libcore/luni-kernel/src/main/java/java/lang/reflect/Method.java index 7fc032229..473726ded 100644 --- a/libcore/luni-kernel/src/main/java/java/lang/reflect/Method.java +++ b/libcore/luni-kernel/src/main/java/java/lang/reflect/Method.java @@ -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; diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java b/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java index 83505e1b6..2ea0b5abb 100644 --- a/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java +++ b/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java @@ -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(';'); diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java b/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java index 855327652..70f05b492 100644 --- a/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java +++ b/libcore/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java @@ -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); } diff --git a/libcore/nio/src/main/java/java/nio/Buffer.java b/libcore/nio/src/main/java/java/nio/Buffer.java index 844d2ce25..9e870e49f 100644 --- a/libcore/nio/src/main/java/java/nio/Buffer.java +++ b/libcore/nio/src/main/java/java/nio/Buffer.java @@ -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. diff --git a/libcore/nio/src/main/java/java/nio/IntToByteBufferAdapter.java b/libcore/nio/src/main/java/java/nio/IntToByteBufferAdapter.java index e52f6b6ce..91b931127 100644 --- a/libcore/nio/src/main/java/java/nio/IntToByteBufferAdapter.java +++ b/libcore/nio/src/main/java/java/nio/IntToByteBufferAdapter.java @@ -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() { diff --git a/libcore/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java b/libcore/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java index fe4fff475..41ce50c3d 100644 --- a/libcore/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java +++ b/libcore/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java @@ -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() { diff --git a/libcore/xml/src/main/java/org/xml/sax/ext/Attributes2Impl.java b/libcore/xml/src/main/java/org/xml/sax/ext/Attributes2Impl.java index 81b9b93e8..fc3680587 100644 --- a/libcore/xml/src/main/java/org/xml/sax/ext/Attributes2Impl.java +++ b/libcore/xml/src/main/java/org/xml/sax/ext/Attributes2Impl.java @@ -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]; diff --git a/libcore/xml/src/test/java/tests/api/org/xml/sax/ext/Attributes2ImplTest.java b/libcore/xml/src/test/java/tests/api/org/xml/sax/ext/Attributes2ImplTest.java index cd1b8720b..9ccdc8a9e 100644 --- a/libcore/xml/src/test/java/tests/api/org/xml/sax/ext/Attributes2ImplTest.java +++ b/libcore/xml/src/test/java/tests/api/org/xml/sax/ext/Attributes2ImplTest.java @@ -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);