Skip to content
Permalink
Browse files
8244146: javac changes for JEP 306
8266399: Core libs update for JEP 306

Reviewed-by: sadayapalam, bpb, naoto
  • Loading branch information
jddarcy committed Jun 1, 2021
1 parent c2c0208 commit 0ae4ceb413a7ea92a41cd55cd338f866098eb9b4
Showing with 578 additions and 56 deletions.
  1. +5 −6 src/java.base/share/classes/java/lang/FdLibm.java
  2. +4 −9 src/java.base/share/classes/java/lang/StrictMath.java
  3. +9 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java
  4. +2 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java
  5. +19 −0 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
  6. +2 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ConstFold.java
  7. +5 −0 src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
  8. +7 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java
  9. +6 −3 src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
  10. +3 −0 src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties
  11. +3 −3 src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java
  12. +4 −4 test/jdk/java/lang/reflect/Method/GenericStringTest.java
  13. +2 −1 test/langtools/tools/javac/7166455/CheckACC_STRICTFlagOnclinitTest.java
  14. +3 −2 test/langtools/tools/javac/8005931/CheckACC_STRICTFlagOnPkgAccessClassTest.java
  15. +3 −2 test/langtools/tools/javac/FloatingPointChanges/BadConstructorModifiers.java
  16. +1 −1 test/langtools/tools/javac/FloatingPointChanges/BadConstructorModifiers.out
  17. +2 −2 test/langtools/tools/javac/T6397044.java
  18. +3 −2 test/langtools/tools/javac/annotations/AnnotationTypeElementModifiers.java
  19. +10 −10 test/langtools/tools/javac/annotations/AnnotationTypeElementModifiers.out
  20. +2 −2 test/langtools/tools/javac/annotations/typeAnnotations/classfile/NestedLambdasCastedTest.java
  21. +2 −1 test/langtools/tools/javac/defaultMethods/CheckACC_STRICTFlagOnDefaultMethodTest.java
  22. +28 −0 test/langtools/tools/javac/diags/examples/UnneededStrictfpWarning.java
  23. +3 −1 test/langtools/tools/javac/lambda/LambdaTestStrictFPFlag.java
  24. +51 −0 test/langtools/tools/javac/processing/model/element/ObsoleteStrictfp/StrictfpHost.java
  25. +36 −0 test/langtools/tools/javac/processing/model/element/ObsoleteStrictfp/StrictfpInSource.java
  26. +98 −0 test/langtools/tools/javac/processing/model/element/ObsoleteStrictfp/TestStrictfpRetention.java
  27. +3 −3 test/langtools/tools/javac/processing/model/element/TestExecutableElement.java
  28. +262 −0 test/langtools/tools/javac/warnings/UnneededStrictfpWarningToolBox.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, 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
@@ -120,7 +120,7 @@ private Cbrt() {
throw new UnsupportedOperationException();
}

public static strictfp double compute(double x) {
public static double compute(double x) {
double t = 0.0;
double sign;

@@ -203,7 +203,7 @@ private Hypot() {
throw new UnsupportedOperationException();
}

public static strictfp double compute(double x, double y) {
public static double compute(double x, double y) {
double a = Math.abs(x);
double b = Math.abs(y);

@@ -343,7 +343,7 @@ private Pow() {
throw new UnsupportedOperationException();
}

public static strictfp double compute(final double x, final double y) {
public static double compute(final double x, final double y) {
double z;
double r, s, t, u, v, w;
int i, j, k, n;
@@ -680,8 +680,7 @@ private Exp() {
throw new UnsupportedOperationException();
}

// should be able to forgo strictfp due to controlled over/underflow
public static strictfp double compute(double x) {
public static double compute(double x) {
double y;
double hi = 0.0;
double lo = 0.0;
@@ -86,7 +86,6 @@
* @author Joseph D. Darcy
* @since 1.3
*/

public final class StrictMath {

/**
@@ -207,10 +206,8 @@ private StrictMath() {}
* @return the measurement of the angle {@code angdeg}
* in radians.
*/
public static strictfp double toRadians(double angdeg) {
// Do not delegate to Math.toRadians(angdeg) because
// this method has the strictfp modifier.
return angdeg * DEGREES_TO_RADIANS;
public static double toRadians(double angdeg) {
return Math.toRadians(angdeg);
}

/**
@@ -224,10 +221,8 @@ public static strictfp double toRadians(double angdeg) {
* @return the measurement of the angle {@code angrad}
* in degrees.
*/
public static strictfp double toDegrees(double angrad) {
// Do not delegate to Math.toDegrees(angrad) because
// this method has the strictfp modifier.
return angrad * RADIANS_TO_DEGREES;
public static double toDegrees(double angrad) {
return Math.toDegrees(angrad);
}

/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@@ -118,6 +118,9 @@ protected Lint(Context context) {
if (source.compareTo(Source.JDK9) >= 0) {
values.add(LintCategory.DEP_ANN);
}
if (Source.Feature.REDUNDANT_STRICTFP.allowedInSource(source)) {
values.add(LintCategory.STRICTFP);
}
values.add(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC);
values.add(LintCategory.OPENS);
values.add(LintCategory.MODULE);
@@ -283,6 +286,11 @@ public String toString() {
*/
STATIC("static"),

/**
* Warn about unnecessary uses of the strictfp modifier
*/
STRICTFP("strictfp"),

/**
* Warn about synchronization attempts on instances of @ValueBased classes.
*/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
@@ -224,6 +224,7 @@ public Target requiredTarget() {
REIFIABLE_TYPES_INSTANCEOF(JDK16, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
RECORDS(JDK16, Fragments.FeatureRecords, DiagKind.PLURAL),
SEALED_CLASSES(JDK17, Fragments.FeatureSealedClasses, DiagKind.PLURAL),
REDUNDANT_STRICTFP(JDK17),
;

enum DiagKind {
@@ -1211,6 +1211,9 @@ else if ((sym.owner.flags_field & INTERFACE) != 0)
} else {
mask = MethodFlags;
}
if ((flags & STRICTFP) != 0) {
warnOnExplicitStrictfp(pos);
}
// Imply STRICTFP if owner has STRICTFP set.
if (((flags|implicit) & Flags.ABSTRACT) == 0 ||
((flags) & Flags.DEFAULT) != 0)
@@ -1252,6 +1255,9 @@ else if ((sym.owner.flags_field & INTERFACE) != 0)
mask &= ~ABSTRACT;
implicit |= FINAL;
}
if ((flags & STRICTFP) != 0) {
warnOnExplicitStrictfp(pos);
}
// Imply STRICTFP if owner has STRICTFP set.
implicit |= sym.owner.flags_field & STRICTFP;
break;
@@ -1314,6 +1320,19 @@ else if ((sym.kind == TYP ||
return flags & (mask | ~ExtendedStandardFlags) | implicit;
}

private void warnOnExplicitStrictfp(DiagnosticPosition pos) {
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(pos);
try {
deferredLintHandler.report(() -> {
if (lint.isEnabled(LintCategory.STRICTFP)) {
log.warning(LintCategory.STRICTFP,
pos, Warnings.Strictfp); }
});
} finally {
deferredLintHandler.setPos(prevLintPos);
}
}


/** Determine if this enum should be implicitly final.
*
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, 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
@@ -41,6 +41,7 @@
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
@SuppressWarnings("strictfp")
strictfp class ConstFold {
protected static final Context.Key<ConstFold> constFoldKey = new Context.Key<>();

@@ -40,6 +40,7 @@
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Attribute.RetentionPolicy;
import com.sun.tools.javac.code.Directive.*;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.code.Types.SignatureGenerator.InvalidSignatureException;
@@ -1697,6 +1698,10 @@ protected int writeExtraAttributes(Symbol sym) {
int adjustFlags(final long flags) {
int result = (int)flags;

// Elide strictfp bit in class files
if (target.obsoleteAccStrict())
result &= ~STRICTFP;

if ((flags & BRIDGE) != 0)
result |= ACC_BRIDGE;
if ((flags & VARARGS) != 0)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
@@ -194,4 +194,10 @@ public boolean hasVirtualPrivateInvoke() {
public boolean hasSealedClasses() {
return compareTo(JDK1_15) >= 0;
}

/** Is the ACC_STRICT bit redundant and obsolete
*/
public boolean obsoleteAccStrict() {
return compareTo(JDK1_17) >= 0;
}
}
@@ -564,10 +564,10 @@ compiler.err.foreach.not.applicable.to.type=\
found: {0}

compiler.err.fp.number.too.large=\
floating point number too large
floating-point number too large

compiler.err.fp.number.too.small=\
floating point number too small
floating-point number too small

compiler.err.generic.array.creation=\
generic array creation
@@ -785,7 +785,7 @@ compiler.err.limit.string.overflow=\
UTF8 representation for string \"{0}...\" is too long for the constant pool

compiler.err.malformed.fp.lit=\
malformed floating point literal
malformed floating-point literal

compiler.err.method.does.not.override.superclass=\
method does not override or implement a method from a supertype
@@ -1764,6 +1764,9 @@ compiler.warn.dir.path.element.not.directory=\
compiler.warn.missing-explicit-ctor=\
class {0} in exported package {1} declares no explicit constructors, thereby exposing a default constructor to clients of module {2}

compiler.warn.strictfp=\
as of release 17, all floating-point expressions are evaluated strictly and ''strictfp'' is not required

compiler.warn.finally.cannot.complete=\
finally clause cannot complete normally

@@ -246,6 +246,9 @@ javac.opt.Xlint.desc.serial=\
javac.opt.Xlint.desc.static=\
Warn about accessing a static member using an instance.

javac.opt.Xlint.desc.strictfp=\
Warn about unnecessary use of the strictfp modifier.

javac.opt.Xlint.desc.text-blocks=\
Warn about inconsistent white space characters in text block indentation.

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@@ -167,7 +167,7 @@ MemoryFileManager fileManager() {
List<String> allOptions = new ArrayList<>();

allOptions.add("--should-stop=at=FLOW");
allOptions.add("-Xlint:unchecked");
allOptions.add("-Xlint:unchecked,-strictfp");
allOptions.add("-proc:none");
allOptions.addAll(extraArgs);

@@ -184,7 +184,7 @@ MemoryFileManager fileManager() {

return runTask(wraps.stream(),
sh,
List.of("-Xlint:unchecked", "-proc:none", "-parameters"),
List.of("-Xlint:unchecked,-strictfp", "-proc:none", "-parameters"),
(jti, diagnostics) -> new CompileTask(sh, jti, diagnostics),
worker);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, 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
@@ -179,10 +179,10 @@ void varArg(Object ... arg) {}
default <A> A bar(){return null;}

@ExpectedString(
"public default strictfp double TestInterface1.quux()")
"public default double TestInterface1.quux()")
@ExpectedGenericString(
"public default strictfp double TestInterface1.quux()")
strictfp default double quux(){return 1.0;}
"public default double TestInterface1.quux()")
default double quux(){return 1.0;}
}

@Retention(RetentionPolicy.RUNTIME)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@@ -26,6 +26,7 @@
* @bug 7166455
* @summary javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
* @modules jdk.jdeps/com.sun.tools.classfile
* @compile -source 16 -target 16 CheckACC_STRICTFlagOnclinitTest.java
* @run main CheckACC_STRICTFlagOnclinitTest
*/

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@@ -81,7 +81,8 @@ private void run(JavaCompiler comp)
}

private void compile(JavaCompiler comp) {
JavacTask ct = (JavacTask)comp.getTask(null, null, null, null, null,
JavacTask ct = (JavacTask)comp.getTask(null, null, null,
List.of("--release", "16"), null,
Arrays.asList(source));
try {
if (!ct.call()) {
@@ -1,10 +1,11 @@
/*
* @test /nodynamiccopyright/
* @bug 4153038 4785453
* @bug 4153038 4785453 8244146
* @summary strictfp may not be used with constructors
* @author David Stoutamire (dps)
*
* @compile/fail/ref=BadConstructorModifiers.out -XDrawDiagnostics BadConstructorModifiers.java
* @compile/fail/ref=BadConstructorModifiers.out -XDrawDiagnostics --release 16 BadConstructorModifiers.java
* @compile/fail/ref=BadConstructorModifiers.out -XDrawDiagnostics -Xlint:-strictfp BadConstructorModifiers.java
*/

public class BadConstructorModifiers {
@@ -1,2 +1,2 @@
BadConstructorModifiers.java:12:14: compiler.err.mod.not.allowed.here: strictfp
BadConstructorModifiers.java:13:14: compiler.err.mod.not.allowed.here: strictfp
1 error
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, 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
@@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception {
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files
= fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
JavacTask task = tool.getTask(null, fm, null, List.of("--release", "16"), null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
Checker checker = new Checker();
for (CompilationUnitTree tree: trees)
@@ -1,8 +1,9 @@
/*
* @test /nodynamiccopyright/
* @bug 8028428
* @bug 8028428 8244146
* @summary Test that only 'public' and 'abstract' elements compile
* @compile/fail/ref=AnnotationTypeElementModifiers.out -XDrawDiagnostics AnnotationTypeElementModifiers.java
* @compile/fail/ref=AnnotationTypeElementModifiers.out -XDrawDiagnostics --release 16 AnnotationTypeElementModifiers.java
* @compile/fail/ref=AnnotationTypeElementModifiers.out -XDrawDiagnostics -Xlint:-strictfp AnnotationTypeElementModifiers.java
*/

public @interface AnnotationTypeElementModifiers {
Loading

1 comment on commit 0ae4ceb

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 0ae4ceb Jun 1, 2021

Please sign in to comment.