aboutsummaryrefslogtreecommitdiff
path: root/test/vm
diff options
context:
space:
mode:
authorduke <none@none>2007-12-01 00:00:00 +0000
committerduke <none@none>2007-12-01 00:00:00 +0000
commit59308f67f9b7038cfa2ceb9ee9ba27645b927cb5 (patch)
tree182810ab2fece13f57a928d026f93e9ede0827f9 /test/vm
Initial loadjdk7-b24
Diffstat (limited to 'test/vm')
-rw-r--r--test/vm/verifier/VerifyProtectedConstructor.java128
-rw-r--r--test/vm/verifier/VerifyStackForExceptionHandlers.java130
2 files changed, 258 insertions, 0 deletions
diff --git a/test/vm/verifier/VerifyProtectedConstructor.java b/test/vm/verifier/VerifyProtectedConstructor.java
new file mode 100644
index 000000000..f2c6f7191
--- /dev/null
+++ b/test/vm/verifier/VerifyProtectedConstructor.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+/**
+ * @test
+
+ * @bug 6490436
+ * @summary Verify that protected constructor calls are not allowed for classfile version >= 50 (but that they are allowed for lesser versions).
+ * @author Keith McGuigan
+ */
+
+public class VerifyProtectedConstructor extends ClassLoader {
+ public static void main(String argv[]) throws Exception {
+ VerifyProtectedConstructor t = new VerifyProtectedConstructor();
+
+ t.loadSuperClass();
+
+ try {
+ t.checkClassVersion(49); // should not throw VerifyError
+ }
+ catch(VerifyError e) {
+ throw new Exception("FAIL: should be no VerifyError for CF version 49");
+ }
+
+ try {
+ t.checkClassVersion(50); // should throw VerifyError
+ throw new Exception("FAIL: should be a VerifyError for CF version 50");
+ }
+ catch(VerifyError e) {
+ System.out.println("PASS");
+ }
+ }
+
+ private void loadSuperClass() {
+ /* -- code for super class A.A --
+ package A;
+ public class A {
+ protected A() {}
+ }
+ */
+ long[] cls_data = {
+ 0xcafebabe00000032L, 0x000a0a0003000707L,
+ 0x0008070009010006L, 0x3c696e69743e0100L,
+ 0x0328295601000443L, 0x6f64650c00040005L,
+ 0x010003412f410100L, 0x106a6176612f6c61L,
+ 0x6e672f4f626a6563L, 0x7400210002000300L,
+ 0x0000000001000400L, 0x0400050001000600L,
+ 0x0000110001000100L, 0x0000052ab70001b1L,
+ 0x0000000000000000L // 2 bytes extra
+ };
+ final int EXTRA = 2;
+ byte cf_bytes[] = toByteArray(cls_data);
+ defineClass("A.A", cf_bytes, 0, cf_bytes.length - EXTRA);
+ }
+
+ private int num_calls;
+ private static String classNames[] = { "B.B", "C.C" };
+
+ private void checkClassVersion(int version) throws VerifyError {
+ // This class is in violation of the spec since it accesses
+ // a protected constructor of a superclass while not being in the
+ // same package.
+ /* -- code for test class --
+ package B;
+ public class B extends A.A {
+ public static void f() { new A.A(); }
+ }
+ */
+ long[] cls_data = {
+ 0xcafebabe00000032L, 0x000b0a0002000807L,
+ 0x000907000a010006L, 0x3c696e69743e0100L,
+ 0x0328295601000443L, 0x6f6465010001660cL,
+ 0x0004000501000341L, 0x2f41010003422f42L,
+ 0x0021000300020000L, 0x0000000200010004L,
+ 0x0005000100060000L, 0x0011000100010000L,
+ 0x00052ab70001b100L, 0x0000000009000700L,
+ 0x0500010006000000L, 0x1500020000000000L,
+ 0x09bb000259b70001L, 0x57b1000000000000L // no extra bytes
+ };
+ final int EXTRA = 0;
+
+ byte cf_bytes[] = toByteArray(cls_data);
+
+ // set version
+ cf_bytes[7] = (byte)version;
+
+ // Change B.B to C.C, D.D, ... for subsequent calls so we can call this
+ // multiple times and define different classes.
+ cf_bytes[61] += num_calls;
+ cf_bytes[63] += num_calls;
+ String name = classNames[num_calls];
+ num_calls++;
+
+ Class c = defineClass(name, cf_bytes, 0, cf_bytes.length - EXTRA);
+
+ try { c.newInstance(); } // to force linking, thus verification
+ catch(InstantiationException e) {}
+ catch(IllegalAccessException e) {}
+ }
+
+ static private byte[] toByteArray(long arr[]) {
+ // convert long array to byte array
+ java.nio.ByteBuffer bbuf = java.nio.ByteBuffer.allocate(arr.length * 8);
+ bbuf.asLongBuffer().put(java.nio.LongBuffer.wrap(arr));
+ return bbuf.array();
+ }
+}
diff --git a/test/vm/verifier/VerifyStackForExceptionHandlers.java b/test/vm/verifier/VerifyStackForExceptionHandlers.java
new file mode 100644
index 000000000..e3c48649c
--- /dev/null
+++ b/test/vm/verifier/VerifyStackForExceptionHandlers.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+/**
+ * @test
+ * @bug 6547378
+ * @summary Verify that methods with max_stack==0 don't have exception handlers
+ * @author Keith McGuigan
+ */
+
+public class VerifyStackForExceptionHandlers extends ClassLoader {
+ public static void main(String argv[]) throws Exception {
+ VerifyStackForExceptionHandlers t =
+ new VerifyStackForExceptionHandlers();
+
+ try {
+ t.loadGoodClass();
+ } catch(VerifyError e) {
+ throw new Exception("FAIL: should be no VerifyError for class A");
+ }
+
+ try {
+ t.loadBadClass();
+ throw new Exception("FAIL: should be a VerifyError for class B");
+ } catch(VerifyError e) {
+ System.out.println("PASS");
+ }
+ }
+
+ private void loadGoodClass() {
+ /* -- code for class A --
+ public class A {
+ public static void f() {}
+ }
+ */
+ long[] cls_data = {
+ 0xcafebabe00000031L, 0x000e0a0003000b07L,
+ 0x000c07000d010006L, 0x3c696e69743e0100L,
+ 0x0328295601000443L, 0x6f646501000f4c69L,
+ 0x6e654e756d626572L, 0x5461626c65010001L,
+ 0x6601000a536f7572L, 0x636546696c650100L,
+ 0x06412e6a6176610cL, 0x0004000501000141L,
+ 0x0100106a6176612fL, 0x6c616e672f4f626aL,
+ 0x6563740021000200L, 0x0300000000000200L,
+ 0x0100040005000100L, 0x060000001d000100L,
+ 0x01000000052ab700L, 0x01b1000000010007L,
+ 0x0000000600010000L, 0x0001000900080005L,
+ 0x0001000600000019L, 0x0000000000000001L,
+ 0xb100000001000700L, 0x0000060001000000L,
+ 0x0200010009000000L, 0x02000a0000000000L
+ };
+ final int EXTRA = 5;
+
+ byte cf_bytes[] = toByteArray(cls_data);
+ Class c = defineClass("A", cf_bytes, 0, cf_bytes.length - EXTRA);
+
+ try { c.newInstance(); } // to force linking, thus verification
+ catch(InstantiationException e) {}
+ catch(IllegalAccessException e) {}
+ }
+
+ private void loadBadClass() throws VerifyError {
+ /* -- code for class B --
+ public class B {
+ public static void g() {}
+ public static void f() {
+ // bytecode modified to have a max_stack value of 0
+ try { g(); }
+ catch (NullPointerException e) {}
+ }
+ }
+ */
+ long[] cls_data = {
+ 0xcafebabe00000031L, 0x00120a000400060aL,
+ 0x000d00030c000f00L, 0x0a0700050100106aL,
+ 0x6176612f6c616e67L, 0x2f4f626a6563740cL,
+ 0x0011000a01000a53L, 0x6f7572636546696cL,
+ 0x6507000901001e6aL, 0x6176612f6c616e67L,
+ 0x2f4e756c6c506f69L, 0x6e74657245786365L,
+ 0x7074696f6e010003L, 0x282956010006422eL,
+ 0x6a61736d01000443L, 0x6f646507000e0100L,
+ 0x0142010001670100L, 0x01660100063c696eL,
+ 0x69743e0021000d00L, 0x0400000000000300L,
+ 0x010011000a000100L, 0x0c00000011000100L,
+ 0x01000000052ab700L, 0x01b1000000000009L,
+ 0x000f000a0001000cL, 0x0000000d00000000L,
+ 0x00000001b1000000L, 0x0000090010000a00L,
+ 0x01000c0000001c00L, 0x00000100000008b8L,
+ 0x0002a700044bb100L, 0x0100000003000600L,
+ 0x0800000001000700L, 0x000002000b000000L // 3 bytes extra
+
+ };
+ final int EXTRA = 3;
+
+ byte cf_bytes[] = toByteArray(cls_data);
+ Class c = defineClass("B", cf_bytes, 0, cf_bytes.length - EXTRA);
+
+ try { c.newInstance(); } // to force linking, thus verification
+ catch(InstantiationException e) {}
+ catch(IllegalAccessException e) {}
+ }
+
+ static private byte[] toByteArray(long arr[]) {
+ // convert long array to byte array
+ java.nio.ByteBuffer bbuf = java.nio.ByteBuffer.allocate(arr.length * 8);
+ bbuf.asLongBuffer().put(java.nio.LongBuffer.wrap(arr));
+ return bbuf.array();
+ }
+ }