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

Multi-Release jar experiments #4521

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ jobs:
access_token: ${{ github.token }}
- name: 'Check out repository'
uses: actions/checkout@v3
- name: 'Set up JDK 11'
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'zulu'
cache: 'maven'
- name: 'Set up JDK 24 from jdk.java.net'
uses: oracle-actions/setup-java@v1
with:
website: jdk.java.net
release: 24
cache: 'maven'
- name: 'Set up JDK ${{ matrix.java }} from jdk.java.net'
if: ${{ matrix.java == 'EA' }}
uses: oracle-actions/setup-java@v1
Expand All @@ -63,9 +75,7 @@ jobs:
if: ${{ matrix.java != 'EA' }}
uses: actions/setup-java@v4
with:
java-version: |
11
${{ matrix.java }}
java-version: ${{ matrix.java }}
distribution: 'zulu'
cache: 'maven'
- name: 'Install'
Expand Down
1 change: 1 addition & 0 deletions bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-fixupmessages: "Classes found in the wrong directory"; restrict:=error; is:=warning
28 changes: 28 additions & 0 deletions check_api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,36 @@
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<jdkToolchain>
<version>11</version>
</jdkToolchain>
</configuration>
</execution>
<execution>
<id>java24</id>
<configuration>
<jdkToolchain>
<version>24</version>
</jdkToolchain>
<!--
<fork>true</fork>
-->
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/java24</compileSourceRoot>
</compileSourceRoots>
<!-- multiReleaseOutput requires setting release -->
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/24</outputDirectory>
</configuration>
</execution>
</executions>

</plugin>
</plugins>

</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 The Error Prone Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.errorprone.util;

import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.Name;

import java.util.Arrays;

import static java.nio.charset.StandardCharsets.UTF_8;

class ErrorProneSignatureGenerator extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected ErrorProneSignatureGenerator(Types types) {
super(types);
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@Override
public String toString() {
// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall once running a benchmark, on the basis of which I concluded that the JVM may be smart enough to conclude that in a scenario such as this one, the String constructor doesn't need to make a defensive copy of the provided array, as it'll hold the only remaining reference. Still, perhaps it's nicer to instead do:

Suggested change
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
return new String(buffer.elems, 0, buffer.length, UTF_8);

(And likewise for the Java 24 variant below.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good point. I had separately been considering refactoring this to pass through a VisitorState to these methods instead of Type, which would allow using buffer.toName(Names) as the comment here notes. I'll take a look at finishing that.

}
}
40 changes: 2 additions & 38 deletions check_api/src/main/java/com/google/errorprone/util/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.errorprone.util;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.joining;

import com.sun.tools.javac.code.BoundKind;
Expand All @@ -25,60 +24,25 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.code.Types.DefaultTypeVisitor;
import com.sun.tools.javac.code.Types.SignatureGenerator;
import com.sun.tools.javac.util.Name;
import java.util.Arrays;

/** Signature generation. */
public final class Signatures {

/** Returns the binary names of the class. */
public static String classDescriptor(Type type, Types types) {
SigGen sig = new SigGen(types);
ErrorProneSignatureGenerator sig = new ErrorProneSignatureGenerator(types);
sig.assembleClassSig(types.erasure(type));
return sig.toString();
}

/** Returns a JVMS 4.3.3 method descriptor. */
public static String descriptor(Type type, Types types) {
SigGen sig = new SigGen(types);
ErrorProneSignatureGenerator sig = new ErrorProneSignatureGenerator(types);
sig.assembleSig(types.erasure(type));
return sig.toString();
}

private static class SigGen extends SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected SigGen(Types types) {
super(types);
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@Override
public String toString() {
// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
}
}

/**
* Pretty-prints a method signature for use in diagnostics.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 The Error Prone Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.errorprone.util;

import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.Name;

import java.util.Arrays;

import static java.nio.charset.StandardCharsets.UTF_8;

class ErrorProneSignatureGenerator extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected ErrorProneSignatureGenerator(Types types) {
types.super();
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@Override
public String toString() {
// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
}
}
22 changes: 21 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
Expand Down Expand Up @@ -264,6 +264,26 @@
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<toolchains>
<jdk>
<version>11</version>
<version>24</version>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Loading