summaryrefslogtreecommitdiffstats
path: root/test/080-oom-throw-with-finalizer
diff options
context:
space:
mode:
authorPavel Vyssotski <pavel.n.vyssotski@intel.com>2014-12-02 19:54:50 +0600
committerPavel Vyssotski <pavel.n.vyssotski@intel.com>2014-12-02 20:53:17 +0600
commit3ac90da48e9cd56eb4b392c7f176e9267d146500 (patch)
treef2ef3b42669aa52130e19b3709afc3239998fdeb /test/080-oom-throw-with-finalizer
parent98646a3d98075da05f9959b2cecea849183dbd27 (diff)
downloadart-3ac90da48e9cd56eb4b392c7f176e9267d146500.zip
art-3ac90da48e9cd56eb4b392c7f176e9267d146500.tar.gz
art-3ac90da48e9cd56eb4b392c7f176e9267d146500.tar.bz2
Fix OOM throwing if it happens in finalizer reference (take 2)
The Class::Alloc should return null if OOM happened during adding finalizer reference, even if finalizable object is allocated succesfully. Added new more reliable test. Change-Id: Id5fed3bdb16297d6d3a2b14ce62cc305aa703d60 Signed-off-by: Dmitry Petrochenko <dmitry.petrochenko@intel.com> Signed-off-by: Serguei Katkov <serguei.i.katkov@intel.com> Signed-off-by: Pavel Vyssotski <pavel.n.vyssotski@intel.com>
Diffstat (limited to 'test/080-oom-throw-with-finalizer')
-rw-r--r--test/080-oom-throw-with-finalizer/expected.txt0
-rw-r--r--test/080-oom-throw-with-finalizer/info.txt1
-rw-r--r--test/080-oom-throw-with-finalizer/src/Main.java71
3 files changed, 72 insertions, 0 deletions
diff --git a/test/080-oom-throw-with-finalizer/expected.txt b/test/080-oom-throw-with-finalizer/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/080-oom-throw-with-finalizer/expected.txt
diff --git a/test/080-oom-throw-with-finalizer/info.txt b/test/080-oom-throw-with-finalizer/info.txt
new file mode 100644
index 0000000..37091ef
--- /dev/null
+++ b/test/080-oom-throw-with-finalizer/info.txt
@@ -0,0 +1 @@
+Regression test on correct processing of OOM thrown while adding a finalizer reference.
diff --git a/test/080-oom-throw-with-finalizer/src/Main.java b/test/080-oom-throw-with-finalizer/src/Main.java
new file mode 100644
index 0000000..57e9721
--- /dev/null
+++ b/test/080-oom-throw-with-finalizer/src/Main.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Vector;
+
+public class Main {
+ static char [][] holder;
+
+ static class ArrayMemEater {
+ static boolean sawOome;
+
+ static void blowup(char[][] holder) {
+ try {
+ for (int i = 0; i < holder.length; ++i) {
+ holder[i] = new char[1024 * 1024];
+ }
+ } catch (OutOfMemoryError oome) {
+ ArrayMemEater.sawOome = true;
+ }
+ }
+ }
+
+ static class InstanceFinalizerMemEater {
+ public void finalize() {}
+ }
+
+ static boolean triggerArrayOOM(char[][] holder) {
+ ArrayMemEater.blowup(holder);
+ return ArrayMemEater.sawOome;
+ }
+
+ static boolean triggerInstanceFinalizerOOM() {
+ boolean sawOome = false;
+ try {
+ Vector v = new Vector();
+ while (true) {
+ v.add(new InstanceFinalizerMemEater());
+ }
+ } catch (OutOfMemoryError e) {
+ sawOome = true;
+ }
+ return sawOome;
+ }
+
+ public static void main(String[] args) {
+ // Keep holder alive to make instance OOM happen faster.
+ holder = new char[128 * 1024][];
+ if (!triggerArrayOOM(holder)) {
+ System.out.println("NEW_ARRAY did not throw OOME");
+ }
+
+ if (!triggerInstanceFinalizerOOM()) {
+ System.out.println("NEW_INSTANCE (finalize) did not throw OOME");
+ }
+
+ System.runFinalization();
+ }
+}