changeset 14607:28f55851bf38

8143232: Fix java.lang.invoke bootstrap when specifying COMPILE_THRESHOLD Reviewed-by: vlivanov
author redestad
date Wed, 18 Nov 2015 17:39:40 +0100
parents 05899a336fcd
children aa9e8b3916ae
files src/java.base/share/classes/java/lang/invoke/LambdaForm.java test/java/lang/invoke/CompileThresholdBootstrapTest.java
diffstat 2 files changed, 54 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Wed Nov 18 08:43:52 2015 +0800
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Wed Nov 18 17:39:40 2015 +0100
@@ -1781,23 +1781,27 @@
         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));
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/lang/invoke/CompileThresholdBootstrapTest.java	Wed Nov 18 17:39:40 2015 +0100
@@ -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();
+    }
+}