VerifyStackForExceptionHandlers.java revision 2362
481N/A/*
481N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
481N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
481N/A *
481N/A * This code is free software; you can redistribute it and/or modify it
481N/A * under the terms of the GNU General Public License version 2 only, as
481N/A * published by the Free Software Foundation.
481N/A *
481N/A * This code is distributed in the hope that it will be useful, but WITHOUT
481N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
481N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
481N/A * version 2 for more details (a copy is included in the LICENSE file that
481N/A * accompanied this code).
481N/A *
481N/A * You should have received a copy of the GNU General Public License version
481N/A * 2 along with this work; if not, write to the Free Software Foundation,
481N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
481N/A *
481N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
873N/A * or visit www.oracle.com if you need additional information or have any
481N/A * questions.
481N/A */
481N/A
481N/A
481N/A/**
5236N/A * @test
5728N/A * @bug 6547378
481N/A * @summary Verify that methods with max_stack==0 don't have exception handlers
481N/A * @author Keith McGuigan
481N/A */
481N/A
481N/Apublic class VerifyStackForExceptionHandlers extends ClassLoader {
1920N/A public static void main(String argv[]) throws Exception {
3824N/A VerifyStackForExceptionHandlers t =
3824N/A new VerifyStackForExceptionHandlers();
3824N/A
3824N/A try {
3824N/A t.loadGoodClass();
3824N/A } catch(VerifyError e) {
5728N/A throw new Exception("FAIL: should be no VerifyError for class A");
3824N/A }
3824N/A
3824N/A try {
3824N/A t.loadBadClass();
481N/A throw new Exception("FAIL: should be a VerifyError for class B");
5636N/A } catch(VerifyError e) {
2976N/A System.out.println("PASS");
481N/A }
481N/A }
5636N/A
1304N/A private void loadGoodClass() {
481N/A /* -- code for class A --
481N/A public class A {
2976N/A public static void f() {}
2976N/A }
5173N/A */
2976N/A long[] cls_data = {
2650N/A 0xcafebabe00000031L, 0x000e0a0003000b07L,
5636N/A 0x000c07000d010006L, 0x3c696e69743e0100L,
481N/A 0x0328295601000443L, 0x6f646501000f4c69L,
481N/A 0x6e654e756d626572L, 0x5461626c65010001L,
481N/A 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();
}
}