Skip to content

Commit 283be2b

Browse files
authored
Build on JDK11 by default (#7)
1 parent 98b34a3 commit 283be2b

File tree

5 files changed

+95
-30
lines changed

5 files changed

+95
-30
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
build:
1414
runs-on: ubuntu-latest
1515
steps:
16+
- name: Configure Java
17+
uses: actions/setup-java@v2
18+
with:
19+
distribution: 'adopt'
20+
java-version: '11'
1621
- name: Checkout repository
1722
uses: actions/checkout@v1
1823
- name: Build project

ndarray/pom.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,31 @@
7575
<plugin>
7676
<groupId>org.apache.maven.plugins</groupId>
7777
<artifactId>maven-surefire-plugin</artifactId>
78-
<version>2.22.2</version>
78+
<version>3.0.0-M5</version>
7979
<configuration>
8080
<forkCount>1</forkCount>
8181
<reuseForks>false</reuseForks>
82-
<argLine>-Xmx2G -XX:MaxPermSize=256m</argLine>
82+
<argLine>-Xmx2G</argLine>
8383
<includes>
8484
<include>**/*Test.java</include>
8585
</includes>
86+
<useModulePath>false</useModulePath>
8687
</configuration>
8788
</plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-compiler-plugin</artifactId>
92+
<executions>
93+
<execution>
94+
<id>default-testCompile</id>
95+
<configuration>
96+
<compilerArgs>
97+
<arg>--add-modules=java.desktop</arg> <!-- For AWT usage in benchmarks -->
98+
</compilerArgs>
99+
</configuration>
100+
</execution>
101+
</executions>
102+
</plugin>
88103
</plugins>
89104
</build>
90105

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2022 The TensorFlow Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
=======================================================================
16+
*/
17+
module org.tensorflow.ndarray {
18+
exports org.tensorflow.ndarray;
19+
exports org.tensorflow.ndarray.buffer;
20+
exports org.tensorflow.ndarray.buffer.layout;
21+
exports org.tensorflow.ndarray.index;
22+
23+
// Expose all implementions of our interfaces, so consumers can write custom
24+
// implementations easily by extending from them
25+
exports org.tensorflow.ndarray.impl.buffer.adapter;
26+
exports org.tensorflow.ndarray.impl.buffer.layout;
27+
exports org.tensorflow.ndarray.impl.buffer.misc;
28+
exports org.tensorflow.ndarray.impl.buffer.nio;
29+
exports org.tensorflow.ndarray.impl.buffer.raw;
30+
exports org.tensorflow.ndarray.impl.dense;
31+
exports org.tensorflow.ndarray.impl.dimension;
32+
exports org.tensorflow.ndarray.impl.sequence;
33+
exports org.tensorflow.ndarray.impl.sparse;
34+
exports org.tensorflow.ndarray.impl.sparse.slice;
35+
36+
requires jdk.unsupported; // required by raw buffer implementations using Unsafe
37+
}

ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/raw/UnsafeReference.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,39 @@ static boolean isAvailable() {
3636
theUnsafe.setAccessible(true);
3737
Object instance = theUnsafe.get(null);
3838
if (instance.getClass() == clazz) {
39-
// Validate that this Unsafe instance exposes all methods we need
40-
clazz.getDeclaredMethod("getByte", Object.class, long.class);
41-
clazz.getDeclaredMethod("putByte", Object.class, long.class, byte.class);
42-
clazz.getDeclaredMethod("getShort", Object.class, long.class);
43-
clazz.getDeclaredMethod("putShort", Object.class, long.class, short.class);
44-
clazz.getDeclaredMethod("getInt", Object.class, long.class);
45-
clazz.getDeclaredMethod("putInt", Object.class, long.class, int.class);
46-
clazz.getDeclaredMethod("getLong", Object.class, long.class);
47-
clazz.getDeclaredMethod("putLong", Object.class, long.class, long.class);
48-
clazz.getDeclaredMethod("getFloat", Object.class, long.class);
49-
clazz.getDeclaredMethod("putFloat", Object.class, long.class, float.class);
50-
clazz.getDeclaredMethod("getDouble", Object.class, long.class);
51-
clazz.getDeclaredMethod("putDouble", Object.class, long.class, double.class);
52-
clazz.getDeclaredMethod("getBoolean", Object.class, long.class);
53-
clazz.getDeclaredMethod("putBoolean", Object.class, long.class, boolean.class);
54-
clazz.getDeclaredMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class);
55-
clazz.getDeclaredMethod("arrayBaseOffset", Class.class);
56-
clazz.getDeclaredMethod("arrayIndexScale", Class.class);
39+
checkMethod(clazz, "getByte", Object.class, long.class);
40+
checkMethod(clazz, "putByte", Object.class, long.class, byte.class);
41+
checkMethod(clazz, "getShort", Object.class, long.class);
42+
checkMethod(clazz, "putShort", Object.class, long.class, short.class);
43+
checkMethod(clazz, "getInt", Object.class, long.class);
44+
checkMethod(clazz, "putInt", Object.class, long.class, int.class);
45+
checkMethod(clazz, "getLong", Object.class, long.class);
46+
checkMethod(clazz, "putLong", Object.class, long.class, long.class);
47+
checkMethod(clazz, "getFloat", Object.class, long.class);
48+
checkMethod(clazz, "putFloat", Object.class, long.class, float.class);
49+
checkMethod(clazz, "getDouble", Object.class, long.class);
50+
checkMethod(clazz, "putDouble", Object.class, long.class, double.class);
51+
checkMethod(clazz, "getBoolean", Object.class, long.class);
52+
checkMethod(clazz, "putBoolean", Object.class, long.class, boolean.class);
53+
checkMethod(clazz, "copyMemory", Object.class, long.class, Object.class, long.class, long.class);
54+
checkMethod(clazz, "arrayBaseOffset", Class.class);
55+
checkMethod(clazz, "arrayIndexScale", Class.class);
56+
5757
unsafe = (Unsafe) instance;
5858
}
5959
} catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | SecurityException | IllegalAccessException | ClassCastException ex) {
6060
// Do nothing, keep unsafe as null
6161
}
6262
UNSAFE = unsafe;
6363
}
64+
65+
/**
66+
* Validate that this Unsafe instance exposes this method
67+
*
68+
* ErrorProne does not like that we do nothing with the returned method... but there is nothing to do with it, so disable the check
69+
*/
70+
@SuppressWarnings("ReturnValueIgnored")
71+
private static void checkMethod(Class<?> unsafeClass, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
72+
unsafeClass.getDeclaredMethod(methodName, parameterTypes);
73+
}
6474
}

pom.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434

3535
<properties>
3636
<project.build.sourceEncoding>ASCII</project.build.sourceEncoding>
37-
<maven.compiler.source>1.8</maven.compiler.source>
38-
<maven.compiler.target>1.8</maven.compiler.target>
37+
<maven.compiler.source>11</maven.compiler.source>
38+
<maven.compiler.target>11</maven.compiler.target>
3939
<junit.version>5.6.2</junit.version>
4040
<jmh.version>1.21</jmh.version>
4141
<versions-plugin.version>2.7</versions-plugin.version>
42-
<errorprone.version>2.6.0</errorprone.version>
42+
<errorprone.version>2.10.0</errorprone.version>
4343
<gpg.skip>true</gpg.skip>
4444
</properties>
4545

@@ -141,11 +141,11 @@
141141
</profile>
142142

143143
<profile>
144-
<id>jdk11</id>
144+
<id>jdk17</id>
145145
<properties>
146-
<maven.compiler.source>11</maven.compiler.source>
147-
<maven.compiler.target>11</maven.compiler.target>
148-
<maven.compiler.release>11</maven.compiler.release>
146+
<maven.compiler.source>17</maven.compiler.source>
147+
<maven.compiler.target>17</maven.compiler.target>
148+
<maven.compiler.release>17</maven.compiler.release>
149149
</properties>
150150
</profile>
151151

@@ -156,8 +156,6 @@
156156
<profile>
157157
<id>lint</id>
158158
<activation>
159-
<!-- activate lint checks only on JDK1.9+ (required by Error Prone) -->
160-
<jdk>(1.9,)</jdk>
161159
<!-- custom property to disable link checks on command line (enabled by default) -->
162160
<property>
163161
<name>!lint.skip</name>
@@ -169,7 +167,7 @@
169167
<plugin>
170168
<groupId>org.apache.maven.plugins</groupId>
171169
<artifactId>maven-compiler-plugin</artifactId>
172-
<version>3.8.0</version>
170+
<version>3.9.0</version>
173171
<configuration>
174172
<showWarnings>true</showWarnings>
175173
<fork>true</fork> <!-- Required for JDK16+ -->

0 commit comments

Comments
 (0)