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