< prev index next >

test/hotspot/jtreg/runtime/valhalla/valuetypes/verifier/VerifierValueTypes.java

Print this page


   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 /*
  25  * @test
  26  * @summary test that the right exceptions get thrown for bad value type
  27  *          class files.
  28  * @compile verifierTests.jcod NoArrayCov.jcod NoArrayCovIntf.jcod NoNullVT.jcod
  29  * @run main/othervm -verify -XX:+EnableValhalla VerifierValueTypes
  30  */
  31 
  32 public class VerifierValueTypes {
  33 
  34     public static void runTestVerifyError(String test_name, String message) throws Exception {
  35         System.out.println("Testing: " + test_name);
  36         try {
  37             Class newClass = Class.forName(test_name);

  38         } catch (java.lang.VerifyError e) {
  39             if (!e.getMessage().contains(message)) {
  40                 throw new RuntimeException( "Wrong VerifyError: " + e.getMessage());
  41             }
  42         }
  43     }
  44 
  45     public static void runTestFormatError(String test_name, String message) throws Exception {
  46         System.out.println("Testing: " + test_name);
  47         try {
  48             Class newClass = Class.forName(test_name);

  49         } catch (java.lang.ClassFormatError e) {
  50             if (!e.getMessage().contains(message)) {
  51                 throw new RuntimeException( "Wrong ClassFormatError: " + e.getMessage());
  52             }
  53         }
  54     }
  55 
  56     public static void main(String[] args) throws Exception {
  57 
  58         // Test that a defaultvalue opcode with an out of bounds cp index causes a VerifyError.
  59         runTestVerifyError("defValBadCP", "Illegal constant pool index");
  60 
  61         // Test that ClassFormatError is thrown for a class file, with major version 54, that
  62         // contains a defaultvalue opcode.
  63         runTestFormatError("defValBadMajorVersion", "defaultvalue not supported by this class file version");
  64 
  65         // Test VerifyError is thrown if a defaultvalue's cp entry is not a class.
  66         runTestVerifyError("defValWrongCPType", "Illegal type at constant pool entry");
  67 
  68         // Test that a withfield opcode with an out of bounds cp index causes a VerifyError.
  69         runTestVerifyError("wthFldBadCP", "Illegal constant pool index");
  70 
  71         // Test that VerifyError is thrown if the first operand on the stack is not assignable


  79         // contains a withfield opcode.
  80         runTestFormatError("wthFldBadMajorVersion", "withfield not supported by this class file version");
  81 
  82         // Test VerifyError is thrown if a withfields's cp entry is not a field.
  83         runTestVerifyError("wthFldWrongCPType", "Illegal type at constant pool entry");
  84 
  85         // Test that VerifyError is thrown if the class for a withfields's cp fieldref
  86         // entry is java.lang.Object and the reference on the stack is a value type.
  87         runTestVerifyError("wthFldObject", "must be identical value types");
  88 
  89         // Test VerifyError is thrown if a monitorenter's cp entry is a value type.
  90         runTestVerifyError("monEnterVT", "Bad type on operand stack");
  91 
  92         // Test VerifyError is thrown if a defaultvalue's cp entry is a value type.
  93         // TBD!!!
  94         runTestVerifyError("defValueObj", "Invalid type on operand stack in withfield instruction");
  95 
  96         // Test VerifyError is thrown if a withfield's class operand is not a value type.
  97         runTestVerifyError("withfieldObj", "Bad type on operand stack");
  98 
  99         // Test that an array of value types is not assignable to [Ljava/lang/Object;.
 100         runTestVerifyError("NoArrayCov",
 101             "Type '[QNoArrayCov;' (current frame, stack[1]) is not assignable to '[Ljava/lang/Object;'");
 102 
 103         // Test that an array of value types is not assignable to an array of interfaces.
 104         runTestVerifyError("NoArrayCovIntf",
 105             "Type '[QNoArrayCovIntf;' (current frame, stack[1]) is not assignable to '[LII;'");
 106 
 107         // Test that null is not assignable to a value type.
 108         runTestVerifyError("NoNullVT",
 109             "Type null (current frame, stack[1]) is not assignable to 'QNoNullVT;'");
 110     }
 111 }
   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 /*
  25  * @test
  26  * @summary test that the right exceptions get thrown for bad value type
  27  *          class files.
  28  * @compile verifierTests.jcod NoArrayCov.jcod NoArrayCovIntf.jcod NoNullVT.jcod
  29  * @run main/othervm -verify -XX:+EnableValhalla VerifierValueTypes
  30  */
  31 
  32 public class VerifierValueTypes {
  33 
  34     public static void runTestVerifyError(String test_name, String message) throws Exception {
  35         System.out.println("Testing: " + test_name);
  36         try {
  37             Class newClass = Class.forName(test_name);
  38             throw new RuntimeException("Expected VerifyError exception not thrown");
  39         } catch (java.lang.VerifyError e) {
  40             if (!e.getMessage().contains(message)) {
  41                 throw new RuntimeException("Wrong VerifyError: " + e.getMessage());
  42             }
  43         }
  44     }
  45 
  46     public static void runTestFormatError(String test_name, String message) throws Exception {
  47         System.out.println("Testing: " + test_name);
  48         try {
  49             Class newClass = Class.forName(test_name);
  50             throw new RuntimeException("Expected ClassFormatError exception not thrown");
  51         } catch (java.lang.ClassFormatError e) {
  52             if (!e.getMessage().contains(message)) {
  53                 throw new RuntimeException("Wrong ClassFormatError: " + e.getMessage());
  54             }
  55         }
  56     }
  57 
  58     public static void main(String[] args) throws Exception {
  59 
  60         // Test that a defaultvalue opcode with an out of bounds cp index causes a VerifyError.
  61         runTestVerifyError("defValBadCP", "Illegal constant pool index");
  62 
  63         // Test that ClassFormatError is thrown for a class file, with major version 54, that
  64         // contains a defaultvalue opcode.
  65         runTestFormatError("defValBadMajorVersion", "defaultvalue not supported by this class file version");
  66 
  67         // Test VerifyError is thrown if a defaultvalue's cp entry is not a class.
  68         runTestVerifyError("defValWrongCPType", "Illegal type at constant pool entry");
  69 
  70         // Test that a withfield opcode with an out of bounds cp index causes a VerifyError.
  71         runTestVerifyError("wthFldBadCP", "Illegal constant pool index");
  72 
  73         // Test that VerifyError is thrown if the first operand on the stack is not assignable


  81         // contains a withfield opcode.
  82         runTestFormatError("wthFldBadMajorVersion", "withfield not supported by this class file version");
  83 
  84         // Test VerifyError is thrown if a withfields's cp entry is not a field.
  85         runTestVerifyError("wthFldWrongCPType", "Illegal type at constant pool entry");
  86 
  87         // Test that VerifyError is thrown if the class for a withfields's cp fieldref
  88         // entry is java.lang.Object and the reference on the stack is a value type.
  89         runTestVerifyError("wthFldObject", "must be identical value types");
  90 
  91         // Test VerifyError is thrown if a monitorenter's cp entry is a value type.
  92         runTestVerifyError("monEnterVT", "Bad type on operand stack");
  93 
  94         // Test VerifyError is thrown if a defaultvalue's cp entry is a value type.
  95         // TBD!!!
  96         runTestVerifyError("defValueObj", "Invalid type on operand stack in withfield instruction");
  97 
  98         // Test VerifyError is thrown if a withfield's class operand is not a value type.
  99         runTestVerifyError("withfieldObj", "Bad type on operand stack");
 100 
 101         // Test that an array of value types is not assignable to [Ljava/lang/Object; (Non-covariance).
 102         runTestVerifyError("NoArrayCov",
 103             "Type '[QNoArrayCov;' (current frame, stack[1]) is not assignable to '[Ljava/lang/Object;'");
 104 
 105         // Test that an array of value types is not assignable to an array of interfaces (Non-covariance).
 106         runTestVerifyError("NoArrayCovIntf",
 107             "Type '[QNoArrayCovIntf;' (current frame, stack[1]) is not assignable to '[LII;'");
 108 
 109         // Test that null is not assignable to a value type.
 110         runTestVerifyError("NoNullVT",
 111             "Type null (current frame, stack[1]) is not assignable to 'QNoNullVT;'");
 112     }
 113 }
< prev index next >