From e9b75962b352e24fd6361fcbb2648be726fabaf0 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Wed, 18 Nov 2015 17:39:40 +0100 Subject: [PATCH] 8143232: Fix java.lang.invoke bootstrap when specifying COMPILE_THRESHOLD Reviewed-by: vlivanov --- .../classes/java/lang/invoke/LambdaForm.java | 8 +++- .../invoke/CompileThresholdBootstrapTest.java | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 jdk/test/java/lang/invoke/CompileThresholdBootstrapTest.java diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java index 1ab16ac5c94..2023bfabfde 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java @@ -1781,23 +1781,27 @@ class LambdaForm { NamedFunction idFun; LambdaForm zeForm; NamedFunction zeFun; + + // Create the LFs and NamedFunctions. Precompiling LFs to byte code is needed to break circular + // bootstrap dependency on this method in case we're interpreting LFs if (isVoid) { Name[] idNames = new Name[] { argument(0, L_TYPE) }; idForm = new LambdaForm(idMem.getName(), 1, idNames, VOID_RESULT); + idForm.compileToBytecode(); idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm)); - assert(zeMem == null); zeForm = idForm; zeFun = idFun; } else { Name[] idNames = new Name[] { argument(0, L_TYPE), argument(1, type) }; idForm = new LambdaForm(idMem.getName(), 2, idNames, 1); + idForm.compileToBytecode(); idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm)); - assert(zeMem != null); Object zeValue = Wrapper.forBasicType(btChar).zero(); Name[] zeNames = new Name[] { argument(0, L_TYPE), new Name(idFun, zeValue) }; zeForm = new LambdaForm(zeMem.getName(), 1, zeNames, 1); + zeForm.compileToBytecode(); zeFun = new NamedFunction(zeMem, SimpleMethodHandle.make(zeMem.getInvocationType(), zeForm)); } diff --git a/jdk/test/java/lang/invoke/CompileThresholdBootstrapTest.java b/jdk/test/java/lang/invoke/CompileThresholdBootstrapTest.java new file mode 100644 index 00000000000..8acbe9cde59 --- /dev/null +++ b/jdk/test/java/lang/invoke/CompileThresholdBootstrapTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 8143232 + * @summary Test verifies that LF bootstraps properly when run with COMPILE_THRESHOLD set + * @compile CompileThresholdBootstrapTest.java + * @run testng/othervm -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=30 test.java.lang.invoke.CompileThresholdBootstrapTest + */ +package test.java.lang.invoke; + +import java.lang.invoke.MethodHandles; +import org.testng.*; +import org.testng.annotations.*; + +public final class CompileThresholdBootstrapTest { + + @Test + public void testBootstrap() throws Throwable { + Assert.assertEquals(0, (int)MethodHandles.constant(int.class, (int)0).invokeExact()); + } + + public static void main(String ... args) { + CompileThresholdBootstrapTest test = CompileThresholdBootstrapTest(); + test.testBootstrap(); + } +}