Skip to content

Commit

Permalink
Update to Java 11 (#11512)
Browse files Browse the repository at this point in the history
* Update to Java 11

changelog_begin
changelog_end

* Fix RoundingMode deprecation warnings

* Fix dep-ann warning

* Integer constructor

* JavaX annotation dependency

* javax.xml.bind was removed in Java 11

Using Guava as a replacement, since it is already a project dependency.

* JDK 11 no longer has a separate JRE tree

* Remove unused jdk_nix import

* remove now redundant jdk11_nix

* Java 8 --> 9 increased Instant.now() precision

See https://bugs.openjdk.java.net/browse/JDK-8068730

The precision of `Instant.now()` increased between Java 8 and Java 9.
On Linux and MacOS this doesn't seem to be a problem, as the precision
still seems to be at micro seconds. However, on Windows this now causes
errors of the following form:
```
java.lang.IllegalArgumentException: Conversion of Instant
2021-11-05T13:58:56.726875100Z to microsecond granularity would result
in loss of precision.
```
Suggesting that it now offers sub-microsecond precision.

`TimestampConversion.instantToMicros` had a check to fail if the
conversion lead to a loss of precision. In the specific failing test
case this is not a concern, so this adds a `roundInstantToMicros`
variant that avoids this kind of error.

* TMP round timestamps

* Revert "TMP round timestamps"

This reverts commit af8e261.

* Skip versions before 1.6.0 in migration tests

changelog_begin
changelog_end

Co-authored-by: Andreas Herrmann <[email protected]>
  • Loading branch information
aherrmann-da and aherrmann authored Nov 18, 2021
1 parent 91b4fb9 commit 39a38d3
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 88 deletions.
12 changes: 6 additions & 6 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ build --copt -DGRPC_BAZEL_BUILD
# avoid dreaded "Unrecognized VM option 'CompactStrings'" error
build:linux --javabase=@nixpkgs_java_runtime//:runtime
build:linux --host_javabase=@nixpkgs_java_runtime//:runtime
build:linux --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:linux --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:linux --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:linux --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:darwin --javabase=@nixpkgs_java_runtime//:runtime
build:darwin --host_javabase=@nixpkgs_java_runtime//:runtime
build:darwin --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:darwin --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:darwin --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:darwin --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:windows --javabase=@dadew_java_runtime//:runtime
build:windows --host_javabase=@dadew_java_runtime//:runtime
build:windows --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:windows --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:windows --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:windows --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11

# Do not use a distinct configuration for "host", that is, binaries used
# at build time should be the same as release binaries.
Expand Down
2 changes: 1 addition & 1 deletion .dadew
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bazel",
"cacert",
"curl",
"java-openjdk-8u302",
"ojdkbuild11",
"maven-3.6.1",
"msys2",
"nodejs-12.17.0",
Expand Down
24 changes: 2 additions & 22 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -515,26 +515,6 @@ nixpkgs_package(
repositories = dev_env_nix_repos,
)

#Javadoc
nixpkgs_package(
name = "jdk_nix",
attribute_path = "jdk8",
fail_not_supported = False,
nix_file = "//nix:bazel.nix",
nix_file_deps = common_nix_file_deps,
repositories = dev_env_nix_repos,
)

# To run canton
nixpkgs_package(
name = "jdk11_nix",
attribute_path = "jdk11",
fail_not_supported = False,
nix_file = "//nix:bazel.nix",
nix_file_deps = common_nix_file_deps,
repositories = dev_env_nix_repos,
)

# This only makes sense on Windows so we just put dummy values in the nix fields.
dev_env_tool(
name = "makensis_dev_env",
Expand Down Expand Up @@ -592,11 +572,11 @@ load("//bazel_tools:java.bzl", "dadew_java_configure", "nixpkgs_java_configure")

dadew_java_configure(
name = "dadew_java_runtime",
dadew_path = "java-openjdk-8u302",
dadew_path = "ojdkbuild11",
) if is_windows else None

nixpkgs_java_configure(
attribute_path = "jdk8.home",
attribute_path = "jdk11.home",
nix_file = "//nix:bazel.nix",
nix_file_deps = common_nix_file_deps,
repositories = dev_env_nix_repos,
Expand Down
12 changes: 6 additions & 6 deletions compatibility/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ build --copt -DGRPC_BAZEL_BUILD
# avoid dreaded "Unrecognized VM option 'CompactStrings'" error
build:linux --javabase=@nixpkgs_java_runtime//:runtime
build:linux --host_javabase=@nixpkgs_java_runtime//:runtime
build:linux --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:linux --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:linux --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:linux --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:darwin --javabase=@nixpkgs_java_runtime//:runtime
build:darwin --host_javabase=@nixpkgs_java_runtime//:runtime
build:darwin --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:darwin --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:darwin --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:darwin --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:windows --javabase=@dadew_java_runtime//:runtime
build:windows --host_javabase=@dadew_java_runtime//:runtime
build:windows --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:windows --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:windows --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build:windows --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11

# Do not use a distinct configuration for "host", that is, binaries used
# at build time should be the same as release binaries.
Expand Down
18 changes: 16 additions & 2 deletions compatibility/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ migration_test(
] +
# These tests are fairly slow so on PRs we only run them on Linux
(["head-quick"] if is_linux else []),
versions = stable_versions,
versions = [
version
for version in stable_versions
# We skip versions before 1.6.0. These versions had a bug where ledger
# effective time was stored at higher precision than it should have
# been. See https://github.com/digital-asset/daml/pull/11512#discussion_r751041534
if versions.is_at_least("1.6.0", version)
],
) if not is_windows else None

migration_test(
Expand All @@ -155,7 +162,14 @@ migration_test(
timeout = "eternal",
# Exclusive due to hardcoded postgres ports.
tags = ["exclusive"],
versions = platform_versions,
versions = [
version
for version in platform_versions
# We skip versions before 1.6.0. These versions had a bug where ledger
# effective time was stored at higher precision than it should have
# been. See https://github.com/digital-asset/daml/pull/11512#discussion_r751041534
if versions.is_at_least("1.6.0", version)
],
) if not is_windows else None

[
Expand Down
4 changes: 2 additions & 2 deletions compatibility/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ load("@daml//bazel_tools:java.bzl", "dadew_java_configure", "nixpkgs_java_config

dadew_java_configure(
name = "dadew_java_runtime",
dadew_path = "java-openjdk-8u302",
dadew_path = "ojdkbuild11",
) if is_windows else None

nixpkgs_java_configure(
attribute_path = "jdk8.home",
attribute_path = "jdk11.home",
nix_file = "@daml//nix:bazel.nix",
nix_file_deps = common_nix_file_deps,
repositories = dev_env_nix_repos,
Expand Down
1 change: 1 addition & 0 deletions compiler/repl-service/protos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ java_library(
"@maven//:io_grpc_grpc_core",
"@maven//:io_grpc_grpc_protobuf",
"@maven//:io_grpc_grpc_stub",
"@maven//:javax_annotation_javax_annotation_api",
],
)

Expand Down
1 change: 1 addition & 0 deletions compiler/scenario-service/protos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ java_library(
"@maven//:io_grpc_grpc_core",
"@maven//:io_grpc_grpc_protobuf",
"@maven//:io_grpc_grpc_stub",
"@maven//:javax_annotation_javax_annotation_api",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
package com.daml.lf.data

import scalaz.Order

import java.math.{BigDecimal, BigInteger}
import java.math.{BigDecimal, BigInteger, RoundingMode}

import scala.math.{BigDecimal => BigDec}
import BigDecimal.{ROUND_DOWN, ROUND_HALF_EVEN, ROUND_UNNECESSARY}

import scala.util.Try

Expand Down Expand Up @@ -109,23 +107,23 @@ abstract class NumericModule {
* In case of overflow, returns an error message instead.
*/
final def multiply(scale: Scale, x: Numeric, y: Numeric): Either[String, Numeric] =
checkForOverflow((x multiply y).setScale(scale, ROUND_HALF_EVEN))
checkForOverflow((x multiply y).setScale(scale, RoundingMode.HALF_EVEN))

/** Divides `x` by `y`. The output has the scale `scale`. If rounding must be
* performed, the [[https://en.wikipedia.org/wiki/Rounding#Round_half_to_even> banker's rounding convention]]
* is applied.
* In case of overflow, returns an error message instead.
*/
final def divide(scale: Scale, x: Numeric, y: Numeric): Either[String, Numeric] =
checkForOverflow(x.divide(y, scale, ROUND_HALF_EVEN))
checkForOverflow(x.divide(y, scale, RoundingMode.HALF_EVEN))

/** Returns the integral part of the given decimal, in other words, rounds towards 0.
* In case the result does not fit into a long, returns an error message instead.
*
* ```Requires the scale of `x` and `y` are the same.```
*/
final def toLong(x: Numeric): Either[String, Long] =
Try(x.setScale(0, ROUND_DOWN).longValueExact()).toEither.left.map(_ =>
Try(x.setScale(0, RoundingMode.DOWN).longValueExact()).toEither.left.map(_ =>
s"(Numeric ${x.scale}) ${toString(x)} does not fit into an Int64"
)

Expand All @@ -136,7 +134,7 @@ abstract class NumericModule {
*/
final def round(targetScale: Long, x: Numeric): Either[String, Numeric] =
if (targetScale <= x.scale && x.scale - maxPrecision < targetScale)
checkForOverflow(x.setScale(targetScale.toInt, ROUND_HALF_EVEN).setScale(x.scale))
checkForOverflow(x.setScale(targetScale.toInt, RoundingMode.HALF_EVEN).setScale(x.scale))
else
Left(s"Bad scale $targetScale, must be between ${x.scale - maxPrecision - 1} and ${x.scale}")

Expand All @@ -157,7 +155,7 @@ abstract class NumericModule {
if (!(x.stripTrailingZeros.scale <= scale))
Left(s"Cannot represent ${toString(x)} as (Numeric $scale) without lost of precision")
else
checkForOverflow(x.setScale(scale, ROUND_UNNECESSARY))
checkForOverflow(x.setScale(scale, RoundingMode.UNNECESSARY))

/** Like `fromBigDecimal(Int, BigDecimal)` but with a scala BigDecimal.
*/
Expand Down Expand Up @@ -269,7 +267,7 @@ abstract class NumericModule {
def checkWithinBoundsAndRound(scale: Scale, x: BigDecimal): Either[String, Numeric] =
Either.cond(
x.precision - x.scale <= maxPrecision - scale,
cast(x.setScale(scale, ROUND_HALF_EVEN)),
cast(x.setScale(scale, RoundingMode.HALF_EVEN)),
s"out-of-bounds (Numeric $scale) $x",
)

Expand Down
21 changes: 0 additions & 21 deletions dev-env/windows/manifests/java-openjdk-8u302.json

This file was deleted.

32 changes: 32 additions & 0 deletions dev-env/windows/manifests/ojdkbuild11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"description": "OpenJDK 11 binaries built using source code from the CentOS project",
"homepage": "https://github.com/ojdkbuild/ojdkbuild",
"version": "11.0.12.7-1",
"license": "GPL-2.0-only WITH Classpath-exception-2.0",
"architecture": {
"64bit": {
"url": "https://github.com/ojdkbuild/ojdkbuild/releases/download/java-11-openjdk-11.0.12.7-1/java-11-openjdk-11.0.12.7-1.windows.ojdkbuild.x86_64.zip",
"hash": "656e551e23c1302312e6a497fac3a65fc3ce186bc0a428646ab811294b01a439",
"extract_dir": "java-11-openjdk-11.0.12.7-1.windows.ojdkbuild.x86_64"
}
},
"env_add_path": "bin",
"env_set": {
"JAVA_HOME": "$dir"
},
"checkver": {
"url": "https://github.com/ojdkbuild/ojdkbuild/raw/master/README.md",
"re": "download/(?<folder>(?:java-11-openjdk-)?(?<version>11[\\db.-]+))/(?<url>java-(?<short>[\\d.]+)-openjdk-([\\db.-]+)(.ojdkbuild|.windows){2}).x86_64.zip"
},
"autoupdate": {
"architecture": {
"64bit": {
"url": "https://github.com/ojdkbuild/ojdkbuild/releases/download/$matchFolder/$matchUrl.x86_64.zip",
"extract_dir": "$matchUrl.x86_64"
}
},
"hash": {
"url": "$url.sha256"
}
}
}
2 changes: 2 additions & 0 deletions language-support/java/bindings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ java_library(
"@maven//:io_grpc_grpc_netty",
"@maven//:io_grpc_grpc_protobuf",
"@maven//:io_grpc_grpc_stub",
"@maven//:javax_annotation_javax_annotation_api",
],
)

Expand Down Expand Up @@ -74,6 +75,7 @@ da_java_library(
"@maven//:io_grpc_grpc_netty",
"@maven//:io_grpc_grpc_protobuf",
"@maven//:io_grpc_grpc_stub",
"@maven//:javax_annotation_javax_annotation_api",
"@maven//:org_checkerframework_checker",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static Record fromProto(ValueOuterClass.Record record) {

// FIXME When removing this after the deprecation period is over, make DamlTextMap.Field final
/** @deprecated Use {@link DamlRecord.Field} instead. */
@Deprecated
public static final class Field extends DamlRecord.Field {

public Field(@NonNull String label, @NonNull Value value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ object TimestampConversion {

}

def roundInstantToMicros(t: Instant): Value.Sum.Timestamp = {
instantToMicros(roundToMicros(t, ConversionMode.HalfUp))
}

def toInstant(protoTimestamp: ProtoTimestamp): Instant = {
Instant.ofEpochSecond(protoTimestamp.seconds, protoTimestamp.nanos.toLong)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
def accountCreateCommand(
owner: domain.Party,
number: String,
time: v.Value.Sum.Timestamp = TimestampConversion.instantToMicros(Instant.now),
time: v.Value.Sum.Timestamp = TimestampConversion.roundInstantToMicros(Instant.now),
): domain.CreateCommand[v.Record, domain.TemplateId.OptionalPkg] = {
val templateId = domain.TemplateId(None, "Account", "Account")
val timeValue = v.Value(time)
Expand All @@ -466,7 +466,7 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
def sharedAccountCreateCommand(
owners: Seq[String],
number: String,
time: v.Value.Sum.Timestamp = TimestampConversion.instantToMicros(Instant.now),
time: v.Value.Sum.Timestamp = TimestampConversion.roundInstantToMicros(Instant.now),
): domain.CreateCommand[v.Record, domain.TemplateId.OptionalPkg] = {
val templateId = domain.TemplateId(None, "Account", "SharedAccount")
val timeValue = v.Value(time)
Expand Down
1 change: 1 addition & 0 deletions ledger-service/http-json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ alias(
"//runtime-components/non-repudiation",
"//runtime-components/non-repudiation-postgresql",
"//runtime-components/non-repudiation-testing",
"@maven//:com_google_guava_guava",
"@maven//:io_dropwizard_metrics_metrics_core",
"@maven//:org_scalatest_scalatest_compatible",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object AbstractHttpServiceIntegrationTestFuns {

def sha256(source: Source[ByteString, Any])(implicit mat: Materializer): Try[String] = Try {
import java.security.MessageDigest
import javax.xml.bind.DatatypeConverter
import com.google.common.io.BaseEncoding

val md = MessageDigest.getInstance("SHA-256")
val is = source.runWith(StreamConverters.asInputStream())
Expand All @@ -79,7 +79,7 @@ object AbstractHttpServiceIntegrationTestFuns {

dis.on(false)

DatatypeConverter.printHexBinary(md.digest()).toLowerCase
BaseEncoding.base16().lowerCase().encode(md.digest())
}
}

Expand Down Expand Up @@ -1673,7 +1673,7 @@ abstract class AbstractHttpServiceIntegrationTest
"query by a variant field" in withHttpService { (uri, encoder, _, _) =>
val (alice, headers) = getUniquePartyAndAuthHeaders("Alice")
val accountNumber = "abc123"
val now = TimestampConversion.instantToMicros(Instant.now)
val now = TimestampConversion.roundInstantToMicros(Instant.now)
val nowStr = TimestampConversion.microsToInstant(now).toString
val command: domain.CreateCommand[v.Record, OptionalPkg] =
accountCreateCommand(alice, accountNumber, now)
Expand Down
Loading

0 comments on commit 39a38d3

Please sign in to comment.