1 /* 2 * Copyright (c) 2017, 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 package runtime.valhalla.valuetypes.verifier; 25 26 import java.lang.invoke.*; 27 28 import jdk.experimental.value.MethodHandleBuilder; 29 import sun.hotspot.WhiteBox; 30 31 /** 32 * @test VloadTest 33 * @summary Test vload opcode 34 * @modules java.base/jdk.experimental.value 35 * jdk.incubator.mvt 36 * @library /test/lib 37 * @compile -XDenableValueTypes VloadTest.java 38 * @run main ClassFileInstaller sun.hotspot.WhiteBox 39 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 40 * sun.hotspot.WhiteBox$WhiteBoxPermission 41 * @run main/othervm -Xint -XX:+UseG1GC -Xmx128m -XX:+EnableMVT 42 * -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 43 * runtime.valhalla.valuetypes.verifier.VloadTest 44 */ 45 public class VloadTest { 46 47 public static void main(String[] args) throws Throwable{ 48 testBytecodes(); 49 } 50 51 // Test that vload cannot load an integer. 52 public static void testBytecodes() throws Throwable { 53 try { 54 MethodHandles.Lookup lookup = MethodHandles.lookup(); 55 56 Object array = MethodHandleBuilder.loadCode( 57 lookup, 58 "vloadAnInteger", 59 MethodType.methodType(Object.class, Integer.TYPE), 60 CODE->{ 61 CODE 62 .vload(0) // Attempt to vload an Integer 63 .aconst_null() 64 .areturn(); 65 }).invoke(1000); 66 } catch (Throwable t) { 67 if (!t.getMessage().contains("java.lang.VerifyError: Bad local variable type")) { 68 throw t; 69 } else { 70 System.out.println("Successful detection of vload verification error"); 71 } 72 } 73 } 74 }