jdk/test/vm/verifier/VerifyStackForExceptionHandlers.java
author sundar
Tue, 01 Feb 2011 21:00:09 +0530
changeset 8164 84f2b622b407
parent 5506 202f599c92aa
permissions -rw-r--r--
7015908: 3 javax.script tests fail with openjdk build Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 6547378
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Verify that methods with max_stack==0 don't have exception handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Keith McGuigan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class VerifyStackForExceptionHandlers extends ClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    public static void main(String argv[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
        VerifyStackForExceptionHandlers t =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
            new VerifyStackForExceptionHandlers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
            t.loadGoodClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        } catch(VerifyError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
            throw new Exception("FAIL: should be no VerifyError for class A");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            t.loadBadClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            throw new Exception("FAIL: should be a VerifyError for class B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        } catch(VerifyError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            System.out.println("PASS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private void loadGoodClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        /* -- code for class A --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
           public class A {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
               public static void f() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        long[] cls_data = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            0xcafebabe00000031L, 0x000e0a0003000b07L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            0x000c07000d010006L, 0x3c696e69743e0100L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            0x0328295601000443L, 0x6f646501000f4c69L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            0x6e654e756d626572L, 0x5461626c65010001L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            0x6601000a536f7572L, 0x636546696c650100L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            0x06412e6a6176610cL, 0x0004000501000141L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            0x0100106a6176612fL, 0x6c616e672f4f626aL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            0x6563740021000200L, 0x0300000000000200L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            0x0100040005000100L, 0x060000001d000100L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            0x01000000052ab700L, 0x01b1000000010007L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            0x0000000600010000L, 0x0001000900080005L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            0x0001000600000019L, 0x0000000000000001L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            0xb100000001000700L, 0x0000060001000000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            0x0200010009000000L, 0x02000a0000000000L
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        final int EXTRA = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        byte cf_bytes[] = toByteArray(cls_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        Class c = defineClass("A", cf_bytes, 0, cf_bytes.length - EXTRA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        try { c.newInstance(); } // to force linking, thus verification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        catch(InstantiationException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        catch(IllegalAccessException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private void loadBadClass() throws VerifyError {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        /* -- code for class B --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
           public class B {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
               public static void g() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
               public static void f() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                  // bytecode modified to have a max_stack value of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                  try { g(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                  catch (NullPointerException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        long[] cls_data = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            0xcafebabe00000031L, 0x00120a000400060aL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            0x000d00030c000f00L, 0x0a0700050100106aL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            0x6176612f6c616e67L, 0x2f4f626a6563740cL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            0x0011000a01000a53L, 0x6f7572636546696cL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            0x6507000901001e6aL, 0x6176612f6c616e67L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            0x2f4e756c6c506f69L, 0x6e74657245786365L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            0x7074696f6e010003L, 0x282956010006422eL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            0x6a61736d01000443L, 0x6f646507000e0100L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            0x0142010001670100L, 0x01660100063c696eL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            0x69743e0021000d00L, 0x0400000000000300L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            0x010011000a000100L, 0x0c00000011000100L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            0x01000000052ab700L, 0x01b1000000000009L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            0x000f000a0001000cL, 0x0000000d00000000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            0x00000001b1000000L, 0x0000090010000a00L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            0x01000c0000001c00L, 0x00000100000008b8L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            0x0002a700044bb100L, 0x0100000003000600L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            0x0800000001000700L, 0x000002000b000000L // 3 bytes extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        final int EXTRA = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        byte cf_bytes[] = toByteArray(cls_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Class c = defineClass("B", cf_bytes, 0, cf_bytes.length - EXTRA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        try { c.newInstance(); } // to force linking, thus verification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        catch(InstantiationException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        catch(IllegalAccessException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static private byte[] toByteArray(long arr[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // convert long array to byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        java.nio.ByteBuffer bbuf = java.nio.ByteBuffer.allocate(arr.length * 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        bbuf.asLongBuffer().put(java.nio.LongBuffer.wrap(arr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return bbuf.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }