Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bump the compiler, runtime, and test runtime version to Java 21 #6340

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildSrc/src/main/groovy/io.deephaven.java-open-nio.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id 'java'
}

def runtimeVersion = Integer.parseInt((String)project.findProperty('runtimeVersion') ?: '11')
def testRuntimeVersion = Integer.parseInt((String)project.findProperty('testRuntimeVersion') ?: '11')
def runtimeVersion = Integer.parseInt((String)project.findProperty('runtimeVersion') ?: '21')
def testRuntimeVersion = Integer.parseInt((String)project.findProperty('testRuntimeVersion') ?: '21')

// Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field long java.nio.Buffer.address accessible: module java.base does not "opens java.nio" to unnamed module @5a42bbf4
// at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ plugins {
id 'java'
}

def compilerVersion = Integer.parseInt((String)project.findProperty('compilerVersion') ?: '11')
def compilerVersion = Integer.parseInt((String)project.findProperty('compilerVersion') ?: '21')
def compilerVendor = project.hasProperty('compilerVendor') ? JvmVendorSpec.matching((String)project.property('compilerVendor')): null

def languageLevel = Integer.parseInt((String)project.findProperty('languageLevel') ?: '11')
def runtimeVersion = Integer.parseInt((String)project.findProperty('runtimeVersion') ?: '11')
def runtimeVersion = Integer.parseInt((String)project.findProperty('runtimeVersion') ?: '21')
def runtimeVendor = project.hasProperty('runtimeVendor') ? JvmVendorSpec.matching((String)project.property('runtimeVendor')): null

def testLanguageLevel = Integer.parseInt((String)project.findProperty('testLanguageLevel') ?: '11')
def testRuntimeVersion = Integer.parseInt((String)project.findProperty('testRuntimeVersion') ?: '11')
def testRuntimeVersion = Integer.parseInt((String)project.findProperty('testRuntimeVersion') ?: '21')
def testRuntimeVendor = project.hasProperty('testRuntimeVendor') ? JvmVendorSpec.matching((String)project.property('testRuntimeVendor')): null

if (languageLevel > compilerVersion) {
Expand Down Expand Up @@ -82,14 +82,43 @@ tasks.withType(JavaCompile).configureEach {
if (name == 'compileTestJava') {
devinrsmith marked this conversation as resolved.
Show resolved Hide resolved
if (compilerVersion != testLanguageLevel) {
options.release.set testLanguageLevel
sourceCompatibility = testLanguageLevel
targetCompatibility = testLanguageLevel
}
} else {
if (compilerVersion != languageLevel) {
options.release.set languageLevel
sourceCompatibility = languageLevel
targetCompatibility = languageLevel
}
}
}

tasks.withType(GroovyCompile).configureEach {
javaLauncher.set groovyCompilerLauncher

options.fork = true
options.forkOptions.memoryMaximumSize = '2G'
options.encoding = 'UTF-8'
options.incremental = true
options.compilerArgs << '-parameters'

if (name == 'compileTestGroovy') {
devinrsmith marked this conversation as resolved.
Show resolved Hide resolved
if (compilerVersion != testLanguageLevel) {
options.release.set testLanguageLevel
sourceCompatibility = testLanguageLevel
targetCompatibility = testLanguageLevel
}
} else {
if (compilerVersion != languageLevel) {
options.release.set languageLevel
sourceCompatibility = languageLevel
targetCompatibility = languageLevel
}
}
}


def createCompilerDirectives = tasks.register('createCompilerDirectives') {
def compilerDirectivesFile = project.layout.buildDirectory.file('dh-compiler-directives.txt')
def compilerDirectivesText = new JsonBuilder([{
Expand Down Expand Up @@ -199,10 +228,6 @@ tasks.withType(Test).configureEach {
jvmArgs += compilerArgs(compilerDirectivesFile.singleFile.path) + ["-XX:VMOptionsFile=${vmOptionsFile.singleFile.path}"] + START_OPTS
}

tasks.withType(GroovyCompile).configureEach {
javaLauncher.set groovyCompilerLauncher
}

JavaApplication application = extensions.findByType(JavaApplication)
if (application) {
application.applicationDistribution.into('etc') {
Expand Down
23 changes: 21 additions & 2 deletions clock-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,33 @@ dependencies {
implementation project(':clock')
compileOnly libs.autoservice
annotationProcessor libs.autoservice.compiler

testImplementation libs.assertj
testImplementation platform(libs.junit.bom)
testImplementation libs.junit.jupiter
testRuntimeOnly libs.junit.platform.launcher
}

test {
useJUnitPlatform()
}

// TODO(deephaven-core#6345): Improve build process for jars that depend on JVM internals
// In the meantime, we can be relatively confident this JAR works for the multiple versions of java since we do nightly
// tests with a range of testRuntimeVersions.

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED']
// Explicitly set the source compatibility so gradle will invoke javac with `-source 11` instead of `--release`
sourceCompatibility = 11
// Explicitly unset release so gradle will invoke javac with `-source <languageLevel> -target <languageLevel>`
// instead of `--release <languageLevel>`, which would otherwise produce
// > error: exporting a package from system module java.base is not allowed with --release
options.release.unset()
}

tasks.withType(Javadoc).configureEach {
options.addStringOption('-add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED')
}

tasks.withType(Test).configureEach {
jvmArgs += ['--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED']
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.base.clock;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Instant;

import static org.assertj.core.api.Assertions.assertThat;

class SystemClockJdkInternalMiscVmTest {

private SystemClockJdkInternalMiscVm SUT;

@BeforeEach
void setUp() {
SUT = new SystemClockJdkInternalMiscVm();
}

@Test
void currentTimeMillis() {
assertThat(SUT.currentTimeMillis()).isPositive();
}

@Test
void currentTimeMicros() {
assertThat(SUT.currentTimeMicros()).isPositive();
}

@Test
void currentTimeNanos() {
assertThat(SUT.currentTimeNanos()).isPositive();
}

@Test
void instantMillis() {
assertThat(SUT.instantMillis()).isAfter(Instant.EPOCH);
}

@Test
void instantNanos() {
assertThat(SUT.instantNanos()).isAfter(Instant.EPOCH);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.base.clock;

import org.junit.jupiter.api.Test;

import java.lang.reflect.InvocationTargetException;

import static org.assertj.core.api.Assertions.assertThat;

class SystemClockTest {
@Test
void of() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException,
InstantiationException, IllegalAccessException {
assertThat(SystemClock.of()).isExactlyInstanceOf(SystemClockJdkInternalMiscVm.class);
}

@Test
void serviceLoader() {
assertThat(SystemClock.serviceLoader()).get().isExactlyInstanceOf(SystemClockJdkInternalMiscVm.class);
}
}
24 changes: 22 additions & 2 deletions hotspot-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@ dependencies {
implementation project(':hotspot')
compileOnly libs.autoservice
annotationProcessor libs.autoservice.compiler

testImplementation libs.assertj
testImplementation platform(libs.junit.bom)
testImplementation libs.junit.jupiter
testRuntimeOnly libs.junit.platform.launcher
}

test {
useJUnitPlatform()
}

// TODO(deephaven-core#6345): Improve build process for jars that depend on JVM internals
// In the meantime, we can be relatively confident this JAR works for the multiple versions of java since we do nightly
// tests with a range of testRuntimeVersions.

tasks.withType(JavaCompile).configureEach {
// TODO(deephaven-core#6345): Improve build process for jars that depend on JVM internals
options.compilerArgs += ['--add-exports', 'java.management/sun.management=ALL-UNNAMED']
// Explicitly set the source compatibility so gradle will invoke javac with `-source 11` instead of `--release`
sourceCompatibility = 11
// Explicitly unset release so gradle will invoke javac with `-source <languageLevel> -target <languageLevel>`
// instead of `--release <languageLevel>`, which would otherwise produce
// > error: exporting a package from system module java.management is not allowed with --release
options.release.unset()
}

tasks.withType(Javadoc).configureEach {
options.addStringOption('-add-exports', 'java.management/sun.management=ALL-UNNAMED')
}

tasks.withType(Test).configureEach {
jvmArgs += ['--add-exports', 'java.management/sun.management=ALL-UNNAMED']
}
17 changes: 17 additions & 0 deletions hotspot-impl/src/test/java/io/deephaven/hotspot/HotSpotTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.hotspot;

import io.deephaven.hotspot.impl.HotSpotImpl;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class HotSpotTest {

@Test
void loadImpl() {
assertThat(HotSpot.loadImpl()).get().isExactlyInstanceOf(HotSpotImpl.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.hotspot.impl;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class HotSpotImplTest {

private HotSpotImpl SUT;

@BeforeEach
void setUp() {
SUT = new HotSpotImpl();
}

@Test
void getSafepointCount() {
assertThat(SUT.getSafepointCount()).isNotNegative();
}

@Test
void getTotalSafepointTimeMillis() {
assertThat(SUT.getTotalSafepointTimeMillis()).isNotNegative();
}

@Test
void getSafepointSyncTimeMillis() {
assertThat(SUT.getSafepointSyncTimeMillis()).isNotNegative();
}
}