OSDN Git Service

Throw OutOfMemoryError on oversize array allocs.
authorAndy McFadden <fadden@android.com>
Wed, 15 Jul 2009 23:56:00 +0000 (16:56 -0700)
committerAndy McFadden <fadden@android.com>
Thu, 16 Jul 2009 00:04:16 +0000 (17:04 -0700)
We've been throwing InternalError because of a particular statement in
the JPL that suggests we should be clearing out SoftReferences before
throwing OOM.  That seems unnecessary for an array allocation that we're
rejecting because the total size doesn't fit in a 32-bit integer.

Now we just throw OOM.

vm/alloc/Heap.c

index 01bffa3..c548190 100644 (file)
@@ -148,15 +148,21 @@ void dvmHeapShutdown()
 
 /*
  * We've been asked to allocate something we can't, e.g. an array so
- * large that (length * elementWidth) is larger than 2^31.  We want to
- * throw an OutOfMemoryError, but doing so implies that certain other
- * actions have taken place (like clearing soft references).
+ * large that (length * elementWidth) is larger than 2^31.
  *
- * TODO: for now we just throw an InternalError.
+ * _The Java Programming Language_, 4th edition, says, "you can be sure
+ * that all SoftReferences to softly reachable objects will be cleared
+ * before an OutOfMemoryError is thrown."
+ *
+ * It's unclear whether that holds for all situations where an OOM can
+ * be thrown, or just in the context of an allocation that fails due
+ * to lack of heap space.  For simplicity we just throw the exception.
+ *
+ * (OOM due to actually running out of space is handled elsewhere.)
  */
 void dvmThrowBadAllocException(const char* msg)
 {
-    dvmThrowException("Ljava/lang/InternalError;", msg);
+    dvmThrowException("Ljava/lang/OutOfMemoryError;", msg);
 }
 
 /*