8046060: Different results of floating point multiplication for lambda code block

Propogate strictfp into lambda body

Reviewed-by: vromero, jlahoda
This commit is contained in:
Robert Field 2014-06-20 10:56:47 -07:00
parent fe46aeabb0
commit 5fad815dec
4 changed files with 215 additions and 0 deletions

View file

@ -1992,7 +1992,11 @@ public class LambdaToMethod extends TreeTranslator {
// If instance access isn't needed, make it static. // If instance access isn't needed, make it static.
// Interface instance methods must be default methods. // Interface instance methods must be default methods.
// Lambda methods are private synthetic. // Lambda methods are private synthetic.
// Inherit ACC_STRICT from the enclosing method, or, for clinit,
// from the class.
translatedSym.flags_field = SYNTHETIC | LAMBDA_METHOD | translatedSym.flags_field = SYNTHETIC | LAMBDA_METHOD |
owner.flags_field & STRICTFP |
owner.owner.flags_field & STRICTFP |
PRIVATE | PRIVATE |
(thisReferenced? (inInterface? DEFAULT : 0) : STATIC); (thisReferenced? (inInterface? DEFAULT : 0) : STATIC);

View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 2014, 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 8046060
* @summary Different results of floating point multiplication for lambda code block
*/
strictfp
public class LambdaTestStrictFP {
static double fld = eval(() -> {
double x = Double.longBitsToDouble(0x1e7ee00000000000L);
double y = Double.longBitsToDouble(0x2180101010101010L);
return x * y;
});
public static void main(String args[]) {
double result = eval(() -> {
double x = Double.longBitsToDouble(0x1e7ee00000000000L);
double y = Double.longBitsToDouble(0x2180101010101010L);
return x * y;
});
{
double x = Double.longBitsToDouble(0x1e7ee00000000000L);
double y = Double.longBitsToDouble(0x2180101010101010L);
double z = x * y;
check(z, result, "method");
check(z, fld, "field");
}
}
private static void check(double expected, double got, String where) {
if (got != expected) {
throw new AssertionError(where + ": Non-strictfp " + got + " != " + expected);
}
}
private static double eval(Face arg) {
return arg.m();
}
private interface Face {
double m();
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2014, 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 8046060
* @summary Different results of floating point multiplication for lambda code block
*/
import java.io.*;
import java.net.URL;
import com.sun.tools.classfile.*;
import static com.sun.tools.classfile.AccessFlags.ACC_STRICT;
public class LambdaTestStrictFPFlag {
public static void main(String[] args) throws Exception {
new LambdaTestStrictFPFlag().run();
}
void run() throws Exception {
ClassFile cf = getClassFile("LambdaTestStrictFPFlag$Test.class");
ConstantPool cp = cf.constant_pool;
boolean found = false;
for (Method meth: cf.methods) {
if (meth.getName(cp).startsWith("lambda$")) {
if ((meth.access_flags.flags & ACC_STRICT) == 0) {
throw new Exception("strict flag missing from lambda");
}
found = true;
}
}
if (!found) {
throw new Exception("did not find lambda method");
}
}
ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
URL url = getClass().getResource(name);
InputStream in = url.openStream();
try {
return ClassFile.read(in);
} finally {
in.close();
}
}
class Test {
strictfp void test() {
Face itf = () -> { };
}
}
interface Face {
void m();
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2014, 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 8046060
* @summary Different results of floating point multiplication for lambda code block
*/
public class LambdaTestStrictFPMethod {
public static void main(String args[]) {
new LambdaTestStrictFPMethod().test();
}
strictfp void test() {
double result = eval(() -> {
double x = Double.longBitsToDouble(0x1e7ee00000000000L);
double y = Double.longBitsToDouble(0x2180101010101010L);
return x * y;
});
{
double x = Double.longBitsToDouble(0x1e7ee00000000000L);
double y = Double.longBitsToDouble(0x2180101010101010L);
double z = x * y;
check(z, result, "method");
}
}
strictfp void check(double expected, double got, String where) {
if (got != expected) {
throw new AssertionError(where + ": Non-strictfp " + got + " != " + expected);
}
}
static double eval(Face arg) {
return arg.m();
}
interface Face {
double m();
}
}