Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/vm/verifier/VerifyStackForExceptionHandlers.java
38833 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/**25* @test26* @bug 654737827* @summary Verify that methods with max_stack==0 don't have exception handlers28* @author Keith McGuigan29*/3031public class VerifyStackForExceptionHandlers extends ClassLoader {32public static void main(String argv[]) throws Exception {33VerifyStackForExceptionHandlers t =34new VerifyStackForExceptionHandlers();3536try {37t.loadGoodClass();38} catch(VerifyError e) {39throw new Exception("FAIL: should be no VerifyError for class A");40}4142try {43t.loadBadClass();44throw new Exception("FAIL: should be a VerifyError for class B");45} catch(VerifyError e) {46System.out.println("PASS");47}48}4950private void loadGoodClass() {51/* -- code for class A --52public class A {53public static void f() {}54}55*/56long[] cls_data = {570xcafebabe00000031L, 0x000e0a0003000b07L,580x000c07000d010006L, 0x3c696e69743e0100L,590x0328295601000443L, 0x6f646501000f4c69L,600x6e654e756d626572L, 0x5461626c65010001L,610x6601000a536f7572L, 0x636546696c650100L,620x06412e6a6176610cL, 0x0004000501000141L,630x0100106a6176612fL, 0x6c616e672f4f626aL,640x6563740021000200L, 0x0300000000000200L,650x0100040005000100L, 0x060000001d000100L,660x01000000052ab700L, 0x01b1000000010007L,670x0000000600010000L, 0x0001000900080005L,680x0001000600000019L, 0x0000000000000001L,690xb100000001000700L, 0x0000060001000000L,700x0200010009000000L, 0x02000a0000000000L71};72final int EXTRA = 5;7374byte cf_bytes[] = toByteArray(cls_data);75Class c = defineClass("A", cf_bytes, 0, cf_bytes.length - EXTRA);7677try { c.newInstance(); } // to force linking, thus verification78catch(InstantiationException e) {}79catch(IllegalAccessException e) {}80}8182private void loadBadClass() throws VerifyError {83/* -- code for class B --84public class B {85public static void g() {}86public static void f() {87// bytecode modified to have a max_stack value of 088try { g(); }89catch (NullPointerException e) {}90}91}92*/93long[] cls_data = {940xcafebabe00000031L, 0x00120a000400060aL,950x000d00030c000f00L, 0x0a0700050100106aL,960x6176612f6c616e67L, 0x2f4f626a6563740cL,970x0011000a01000a53L, 0x6f7572636546696cL,980x6507000901001e6aL, 0x6176612f6c616e67L,990x2f4e756c6c506f69L, 0x6e74657245786365L,1000x7074696f6e010003L, 0x282956010006422eL,1010x6a61736d01000443L, 0x6f646507000e0100L,1020x0142010001670100L, 0x01660100063c696eL,1030x69743e0021000d00L, 0x0400000000000300L,1040x010011000a000100L, 0x0c00000011000100L,1050x01000000052ab700L, 0x01b1000000000009L,1060x000f000a0001000cL, 0x0000000d00000000L,1070x00000001b1000000L, 0x0000090010000a00L,1080x01000c0000001c00L, 0x00000100000008b8L,1090x0002a700044bb100L, 0x0100000003000600L,1100x0800000001000700L, 0x000002000b000000L // 3 bytes extra111112};113final int EXTRA = 3;114115byte cf_bytes[] = toByteArray(cls_data);116Class c = defineClass("B", cf_bytes, 0, cf_bytes.length - EXTRA);117118try { c.newInstance(); } // to force linking, thus verification119catch(InstantiationException e) {}120catch(IllegalAccessException e) {}121}122123static private byte[] toByteArray(long arr[]) {124// convert long array to byte array125java.nio.ByteBuffer bbuf = java.nio.ByteBuffer.allocate(arr.length * 8);126bbuf.asLongBuffer().put(java.nio.LongBuffer.wrap(arr));127return bbuf.array();128}129}130131132