OSDN Git Service

am af242824: Revert "Fix a type error in the allocation of non-moving arrays." per...
[android-x86/dalvik.git] / vm / Exception.c
index ddb84e5..b4b7160 100644 (file)
@@ -317,13 +317,13 @@ bail:
 }
 
 /*
- * Throw the named exception using the dotted form of the class
+ * Throw the named exception using the human-readable form of the class
  * descriptor as the exception message, and with the specified cause.
  */
 void dvmThrowChainedExceptionWithClassMessage(const char* exceptionDescriptor,
     const char* messageDescriptor, Object* cause)
 {
-    char* message = dvmDescriptorToDot(messageDescriptor);
+    char* message = dvmHumanReadableDescriptor(messageDescriptor);
 
     dvmThrowChainedException(exceptionDescriptor, message, cause);
     free(message);
@@ -723,6 +723,7 @@ void dvmPrintExceptionStackTrace(void)
     if (exception == NULL)
         return;
 
+    dvmAddTrackedAlloc(exception, self);
     self->exception = NULL;
     printMethod = dvmFindVirtualMethodHierByDescriptor(exception->clazz,
                     "printStackTrace", "()V");
@@ -740,6 +741,7 @@ void dvmPrintExceptionStackTrace(void)
     }
 
     self->exception = exception;
+    dvmReleaseTrackedAlloc(exception, self);
 }
 
 /*
@@ -1156,7 +1158,7 @@ ArrayObject* dvmGetStackTraceRaw(const int* intVals, int stackDepth)
         else
             lineNumber = dvmLineNumFromPC(meth, pc);
 
-        dotName = dvmDescriptorToDot(meth->clazz->descriptor);
+        dotName = dvmHumanReadableDescriptor(meth->clazz->descriptor);
         className = dvmCreateStringFromCstr(dotName);
         free(dotName);
 
@@ -1218,7 +1220,7 @@ void dvmLogRawStackTrace(const int* intVals, int stackDepth)
             lineNumber = dvmLineNumFromPC(meth, pc);
 
         // probably don't need to do this, but it looks nicer
-        dotName = dvmDescriptorToDot(meth->clazz->descriptor);
+        dotName = dvmHumanReadableDescriptor(meth->clazz->descriptor);
 
         if (dvmIsNativeMethod(meth)) {
             LOGI("\tat %s.%s(Native Method)\n", dotName, meth->name);
@@ -1250,6 +1252,7 @@ static StringObject* getExceptionMessage(Object* exception)
     StringObject* messageStr = NULL;
 
     assert(exception == self->exception);
+    dvmAddTrackedAlloc(exception, self);
     self->exception = NULL;
 
     getMessageMethod = dvmFindVirtualMethodHierByDescriptor(exception->clazz,
@@ -1276,6 +1279,7 @@ static StringObject* getExceptionMessage(Object* exception)
     }
 
     self->exception = exception;
+    dvmReleaseTrackedAlloc(exception, self);
     return messageStr;
 }
 
@@ -1290,7 +1294,7 @@ static void logStackTraceOf(Object* exception)
     const int* intVals;
     char* className;
 
-    className = dvmDescriptorToDot(exception->clazz->descriptor);
+    className = dvmHumanReadableDescriptor(exception->clazz->descriptor);
     messageStr = getExceptionMessage(exception);
     if (messageStr != NULL) {
         char* cp = dvmCreateCstrFromString(messageStr);
@@ -1349,3 +1353,33 @@ void dvmLogExceptionStackTrace(void)
         exception = cause;
     }
 }
+
+void dvmThrowAIOOBE(int index, int length)
+{
+    dvmThrowExceptionFmt("Ljava/lang/ArrayIndexOutOfBoundsException;",
+        "index=%d length=%d", index, length);
+}
+
+static void dvmThrowTypeError(const char* exceptionClassName, const char* fmt,
+    ClassObject* actual, ClassObject* desired)
+{
+    char* actualClassName = dvmHumanReadableDescriptor(actual->descriptor);
+    char* desiredClassName = dvmHumanReadableDescriptor(desired->descriptor);
+    dvmThrowExceptionFmt(exceptionClassName, fmt,
+        actualClassName, desiredClassName);
+    free(desiredClassName);
+    free(actualClassName);
+}
+
+void dvmThrowArrayStoreException(ClassObject* actual, ClassObject* desired)
+{
+    dvmThrowTypeError("Ljava/lang/ArrayStoreException;",
+        "%s cannot be stored in an array of type %s",
+        actual, desired);
+}
+
+void dvmThrowClassCastException(ClassObject* actual, ClassObject* desired)
+{
+    dvmThrowTypeError("Ljava/lang/ClassCastException;",
+        "%s cannot be cast to %s", actual, desired);
+}