summaryrefslogtreecommitdiffstats
path: root/test/088-monitor-verification
diff options
context:
space:
mode:
authorjeffhao <jeffhao@google.com>2011-09-29 17:41:15 -0700
committerjeffhao <jeffhao@google.com>2011-09-29 17:41:15 -0700
commit5d1ac920fdaef5d4ec8f66bb734488cd9660b024 (patch)
treedd372f306ab70f4c86759869b1f74eca62ff6f2b /test/088-monitor-verification
parentc31664f3d82e6cd68275a529a8a73f067a52e8be (diff)
downloadart-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.tar.gz
art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.tar.bz2
art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.zip
Adding old unit tests to test suite.
These tests are copied straight over. They'll still run, but they're using the old system. Change-Id: If494519e52ddf858a9febfc55bdae830468cb3c8
Diffstat (limited to 'test/088-monitor-verification')
-rw-r--r--test/088-monitor-verification/expected.txt7
-rw-r--r--test/088-monitor-verification/info.txt2
-rw-r--r--test/088-monitor-verification/src/Main.java221
-rw-r--r--test/088-monitor-verification/src/MyException.java24
-rw-r--r--test/088-monitor-verification/src/TooDeep.java64
5 files changed, 318 insertions, 0 deletions
diff --git a/test/088-monitor-verification/expected.txt b/test/088-monitor-verification/expected.txt
new file mode 100644
index 0000000000..07f5b0be82
--- /dev/null
+++ b/test/088-monitor-verification/expected.txt
@@ -0,0 +1,7 @@
+recursiveSync ok
+nestedMayThrow ok
+constantLock ok
+excessiveNesting ok
+notNested ok
+twoPath ok
+triplet ok
diff --git a/test/088-monitor-verification/info.txt b/test/088-monitor-verification/info.txt
new file mode 100644
index 0000000000..c00cb1c1ff
--- /dev/null
+++ b/test/088-monitor-verification/info.txt
@@ -0,0 +1,2 @@
+Try different arrangements of "synchronized" to exercise the structured
+lock checks in the bytecode verifier.
diff --git a/test/088-monitor-verification/src/Main.java b/test/088-monitor-verification/src/Main.java
new file mode 100644
index 0000000000..aa90b92dae
--- /dev/null
+++ b/test/088-monitor-verification/src/Main.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+
+/*
+ * Entry point and tests that are expected to succeed.
+ */
+public class Main {
+ /**
+ * Drives tests.
+ */
+ public static void main(String[] args) {
+ Main m = new Main();
+
+ m.recursiveSync(0);
+
+ m.nestedMayThrow(false);
+ try {
+ m.nestedMayThrow(true);
+ System.err.println("nestedThrow(true) did not throw");
+ } catch (MyException me) {}
+ System.out.println("nestedMayThrow ok");
+
+ m.constantLock();
+ System.out.println("constantLock ok");
+
+ m.notExcessiveNesting();
+ if (false) { // TODO: remove when verification is turned on
+ try {
+ TooDeep.excessiveNesting();
+ System.err.println("excessiveNesting did not throw");
+ } catch (VerifyError ve) {}
+ }
+ System.out.println("excessiveNesting ok");
+
+ m.notNested();
+ System.out.println("notNested ok");
+
+ Object obj1 = new Object();
+ Object obj2 = new Object();
+
+ m.twoPath(obj1, obj2, 0);
+ System.out.println("twoPath ok");
+
+ m.triplet(obj1, obj2, 0);
+ System.out.println("triplet ok");
+ }
+
+ /**
+ * Recursive synchronized method.
+ */
+ synchronized void recursiveSync(int iter) {
+ if (iter < 40) {
+ recursiveSync(iter+1);
+ } else {
+ System.out.println("recursiveSync ok");
+ }
+ }
+
+ /**
+ * Tests simple nesting, with and without a throw.
+ */
+ void nestedMayThrow(boolean doThrow) {
+ synchronized (this) {
+ synchronized (Main.class) {
+ synchronized (new Object()) {
+ synchronized(Class.class) {
+ if (doThrow) {
+ throw new MyException();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Exercises bug 3215458.
+ */
+ void constantLock() {
+ Class thing = Thread.class;
+ synchronized (Thread.class) {}
+ }
+
+ /**
+ * Confirms that we can have 32 nested monitors on one method.
+ */
+ void notExcessiveNesting() {
+ synchronized (this) { // 1
+ synchronized (this) { // 2
+ synchronized (this) { // 3
+ synchronized (this) { // 4
+ synchronized (this) { // 5
+ synchronized (this) { // 6
+ synchronized (this) { // 7
+ synchronized (this) { // 8
+ synchronized (this) { // 9
+ synchronized (this) { // 10
+ synchronized (this) { // 11
+ synchronized (this) { // 12
+ synchronized (this) { // 13
+ synchronized (this) { // 14
+ synchronized (this) { // 15
+ synchronized (this) { // 16
+ synchronized (this) { // 17
+ synchronized (this) { // 18
+ synchronized (this) { // 19
+ synchronized (this) { // 20
+ synchronized (this) { // 21
+ synchronized (this) { // 22
+ synchronized (this) { // 23
+ synchronized (this) { // 24
+ synchronized (this) { // 25
+ synchronized (this) { // 26
+ synchronized (this) { // 27
+ synchronized (this) { // 28
+ synchronized (this) { // 29
+ synchronized (this) { // 30
+ synchronized (this) { // 31
+ synchronized (this) { // 32
+ }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+ }
+
+ /**
+ * Confirms that we can have more than 32 non-nested monitors in one
+ * method.
+ */
+ void notNested() {
+ synchronized (this) {} // 1
+ synchronized (this) {} // 2
+ synchronized (this) {} // 3
+ synchronized (this) {} // 4
+ synchronized (this) {} // 5
+ synchronized (this) {} // 6
+ synchronized (this) {} // 7
+ synchronized (this) {} // 8
+ synchronized (this) {} // 9
+ synchronized (this) {} // 10
+ synchronized (this) {} // 11
+ synchronized (this) {} // 12
+ synchronized (this) {} // 13
+ synchronized (this) {} // 14
+ synchronized (this) {} // 15
+ synchronized (this) {} // 16
+ synchronized (this) {} // 17
+ synchronized (this) {} // 18
+ synchronized (this) {} // 19
+ synchronized (this) {} // 20
+ synchronized (this) {} // 21
+ synchronized (this) {} // 22
+ synchronized (this) {} // 23
+ synchronized (this) {} // 24
+ synchronized (this) {} // 25
+ synchronized (this) {} // 26
+ synchronized (this) {} // 27
+ synchronized (this) {} // 28
+ synchronized (this) {} // 29
+ synchronized (this) {} // 30
+ synchronized (this) {} // 31
+ synchronized (this) {} // 32
+ synchronized (this) {} // 33
+ synchronized (this) {} // 34
+ }
+
+ /* does nothing but ensure that the compiler doesn't discard an object */
+ private void doNothing(Object obj) {}
+
+ /**
+ * Conditionally uses one of the synchronized objects.
+ */
+ public void twoPath(Object obj1, Object obj2, int x) {
+ Object localObj;
+
+ synchronized (obj1) {
+ synchronized(obj2) {
+ if (x == 0) {
+ localObj = obj2;
+ } else {
+ localObj = obj1;
+ }
+ }
+ }
+
+ doNothing(localObj);
+ }
+
+ /**
+ * Lock the monitor two or three times, and make use of the locked or
+ * unlocked object.
+ */
+ public void triplet(Object obj1, Object obj2, int x) {
+ Object localObj;
+
+ synchronized (obj1) {
+ synchronized(obj1) {
+ if (x == 0) {
+ synchronized(obj1) {
+ localObj = obj2;
+ }
+ } else {
+ localObj = obj1;
+ }
+ }
+ }
+
+ doNothing(localObj);
+ }
+}
diff --git a/test/088-monitor-verification/src/MyException.java b/test/088-monitor-verification/src/MyException.java
new file mode 100644
index 0000000000..cf65d6da43
--- /dev/null
+++ b/test/088-monitor-verification/src/MyException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+public class MyException extends RuntimeException {
+ public MyException() {
+ super();
+ }
+ public MyException(String msg) {
+ super(msg);
+ }
+}
diff --git a/test/088-monitor-verification/src/TooDeep.java b/test/088-monitor-verification/src/TooDeep.java
new file mode 100644
index 0000000000..76192e55c6
--- /dev/null
+++ b/test/088-monitor-verification/src/TooDeep.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+
+/**
+ * The class has a method with too many levels of nested "synchronized"
+ * blocks. The verifier will reject it.
+ *
+ * (It would be perfectly okay if the verifier *didn't* reject this.
+ * The goal here is just to exercise the failure path. It also serves
+ * as a check to see if the monitor checks are enabled.)
+ */
+public class TooDeep {
+
+ public static void excessiveNesting() {
+ synchronized (TooDeep.class) { // 1
+ synchronized (TooDeep.class) { // 2
+ synchronized (TooDeep.class) { // 3
+ synchronized (TooDeep.class) { // 4
+ synchronized (TooDeep.class) { // 5
+ synchronized (TooDeep.class) { // 6
+ synchronized (TooDeep.class) { // 7
+ synchronized (TooDeep.class) { // 8
+ synchronized (TooDeep.class) { // 9
+ synchronized (TooDeep.class) { // 10
+ synchronized (TooDeep.class) { // 11
+ synchronized (TooDeep.class) { // 12
+ synchronized (TooDeep.class) { // 13
+ synchronized (TooDeep.class) { // 14
+ synchronized (TooDeep.class) { // 15
+ synchronized (TooDeep.class) { // 16
+ synchronized (TooDeep.class) { // 17
+ synchronized (TooDeep.class) { // 18
+ synchronized (TooDeep.class) { // 19
+ synchronized (TooDeep.class) { // 20
+ synchronized (TooDeep.class) { // 21
+ synchronized (TooDeep.class) { // 22
+ synchronized (TooDeep.class) { // 23
+ synchronized (TooDeep.class) { // 24
+ synchronized (TooDeep.class) { // 25
+ synchronized (TooDeep.class) { // 26
+ synchronized (TooDeep.class) { // 27
+ synchronized (TooDeep.class) { // 28
+ synchronized (TooDeep.class) { // 29
+ synchronized (TooDeep.class) { // 30
+ synchronized (TooDeep.class) { // 31
+ synchronized (TooDeep.class) { // 32
+ synchronized (TooDeep.class) { // 33
+ }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+ }
+}