--- /dev/null 2017-07-26 09:54:12.369710964 +0200 +++ new/test/compiler/valhalla/valuetypes/TestBoundValueTypes.java 2017-07-26 13:21:53.891680114 +0200 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.valhalla.valuetypes; + + +import java.lang.invoke.*; +import jdk.experimental.value.*; + +/** + * @test + * @bug 8185339 + * @summary Test correct compilation of MethodHandles with bound value type arguments. + * @compile -XDenableValueTypes ValueCapableClass2.java TestBoundValueTypes.java + * @run main/othervm -noverify -XX:+EnableMVT -XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.TestBoundValueTypes::* + * -XX:CompileCommand=compileonly,java.lang.invoke.*::* compiler.valhalla.valuetypes.TestBoundValueTypes + */ +public class TestBoundValueTypes { + static final Object vcc = ValueCapableClass2.create(42L); + + static final MethodHandle mh; + static { + final MethodHandle getX = MethodHandleBuilder.loadCode(MethodHandles.lookup(), "getX", + MethodType.methodType(long.class, ValueType.forClass(ValueCapableClass2.class).valueClass()), + CODE -> { + CODE. + vload(0). + vbox(ValueCapableClass2.class). + vunbox(ValueType.forClass(ValueCapableClass2.class).valueClass()). + vgetfield(ValueType.forClass(ValueCapableClass2.class).valueClass(), "u", "J"). + lreturn(); + }); + // Bind the value type argument to 'vcc' + mh = MethodHandles.insertArguments(getX, 0, vcc); + } + + long test() throws Throwable { + return (long)mh.invoke(); + } + + public static void main(String[] args) throws Throwable { + TestBoundValueTypes t = new TestBoundValueTypes(); + for (int i = 0; i < 100_000; ++i) { + if (t.test() != 42) { + throw new RuntimeException("Test failed"); + } + } + } +}