Skip to content

Commit

Permalink
java 18-20 (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Apr 4, 2024
1 parent 32965bc commit 1814c15
Show file tree
Hide file tree
Showing 59 changed files with 2,514 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ version=0.0.1
asm_version=9.6

mainVersion=7
testVersion=17
testVersion=21

stubFromVersion=9
stubToVersion=17
stubToVersion=21



Expand Down
7 changes: 7 additions & 0 deletions java-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ tasks.compileTestJava {
configCompile(testVersion)
}

tasks.getByName<JavaCompile>("compileCoverageJava") {
configCompile(toVersion)
}

tasks.jar {
from(*((fromVersion..toVersion).map { sourceSets["java${it.ordinal + 1}"].output } + sourceSets.main.get().output).toTypedArray())
}
Expand Down Expand Up @@ -216,6 +220,9 @@ val downgradeJar8 by tasks.registering(Jar::class) {
val coverageReport by tasks.registering(JavaExec::class) {
group = "jvmdg"
dependsOn(tasks.jar)
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(toVersion.majorVersion))
})
mainClass = "xyz.wagyourtail.jvmdg.coverage.CoverageChecker"
classpath = coverage.runtimeClasspath
jvmArgs("-Djvmdg.java-api=${tasks.jar.get().archiveFile.get().asFile.absolutePath}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static void writeList(List<MemberInfo> missing, Path outputFile) throws
try (var writer = Files.newBufferedWriter(outputFile)) {
for (var entry : byModule.entrySet().stream().sorted(Map.Entry.comparingByKey()).toList()) {
var mod = entry.getKey();
for (var stub : entry.getValue()) {
for (var stub : entry.getValue().stream().sorted().toList()) {
writer.write(mod);
writer.write(';');
writer.write(stub);
Expand Down Expand Up @@ -266,6 +266,14 @@ public static void compare(List<Path> moduleHolders, Map<String, Pair<String, Cl
if (cn.name.startsWith("sun/")) {
if (!cn.name.equals("sun/misc/Unsafe")) return;
}
// if class is annotated with @PreviewFeature, skip
if (cn.invisibleAnnotations != null) {
for (var a : cn.invisibleAnnotations) {
if (a.desc.equals("Ljdk/internal/javac/PreviewFeature;") || a.desc.equals("Ljdk/internal/PreviewFeature;")) {
return;
}
}
}
if ((cn.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0) return;
newClasses.put(cn.name, new Pair<>(modName, cn));
if (currentVersion.containsKey(cn.name)) {
Expand All @@ -279,7 +287,7 @@ public static void compare(List<Path> moduleHolders, Map<String, Pair<String, Cl
if (m.name.equals("<clinit>")) continue;
if (m.invisibleAnnotations != null) {
for (var a : m.invisibleAnnotations) {
if (a.desc.equals("Ljdk/internal/PreviewFeature;")) {
if (a.desc.equals("Ljdk/internal/javac/PreviewFeature;") || a.desc.equals("Ljdk/internal/PreviewFeature;")) {
continue outerA;
}
}
Expand All @@ -293,7 +301,7 @@ public static void compare(List<Path> moduleHolders, Map<String, Pair<String, Cl
// is preview feature?
if (m.invisibleAnnotations != null) {
for (var a : m.invisibleAnnotations) {
if (a.desc.equals("Ljdk/internal/PreviewFeature;")) {
if (a.desc.equals("Ljdk/internal/javac/PreviewFeature;") || a.desc.equals("Ljdk/internal/PreviewFeature;")) {
continue outerB;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j14.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.PrintStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package xyz.wagyourtail.jvmdg.j18.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.nio.charset.Charset;

public class J_I_PrintStream {

@Stub
public static Charset charset(PrintStream printStream) throws NoSuchFieldException, IllegalAccessException {
Field charOut = printStream.getClass().getField("charOut");
charOut.setAccessible(true);
OutputStreamWriter writer = (OutputStreamWriter) charOut.get(printStream);
String encoding = writer.getEncoding();
return Charset.forName(encoding);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package xyz.wagyourtail.jvmdg.j18.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

public class J_L_Math {

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long floorDivExact(long x, long y) {
final long q = x / y;
if ((x & y & q) >= 0) {
if ((x ^ y) < 0 && (q * y != x)) {
return q - 1;
}
return q;
}
throw new ArithmeticException("long overflow");
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static int ceilDivExact(int x, int y) {
final int q = x / y;
if ((x & y & q) >= 0) {
if ((x ^ y) >= 0 && (q * y != x)) {
return q + 1;
}
return q;
}
throw new ArithmeticException("integer overflow");
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static int ceilDiv(int x, int y) {
final int q = x / y;
if ((x ^ y) >= 0 && (q * y != x)) {
return q + 1;
}
return q;
}


@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long divideExact(long x, long y) {
long q = x / y;
if ((x & y & q) >= 0) {
return q;
}
throw new ArithmeticException("long overflow");
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long ceilDiv(long x, long y) {
final long q = x / y;
if ((x ^ y) >= 0 && (q * y != x)) {
return q + 1;
}
return q;
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long unsignedMultiplyHigh(long x, long y) {
long result = Math.multiplyHigh(x, y);
result += (y & (x >> 63));
result += (x & (y >> 63));
return result;
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long ceilMod(long x, long y) {
final long r = x % y;
if ((x ^ y) >= 0 && r != 0) {
return r - y;
}
return r;
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static int ceilMod(long x, int y) {
return (int) ceilMod(x, (long) y);
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static int floorDivExact(int x, int y) {
final int q = x / y;
if ((x & y & q) >= 0) {
if ((x ^ y) < 0 && (q * y != x)) {
return q - 1;
}
return q;
}
throw new ArithmeticException("integer overflow");
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long ceilDivExact(long x, long y) {
final long q = x / y;
if ((x & y & q) >= 0) {
if ((x ^ y) >= 0 && (q * y != x)) {
return q + 1;
}
return q;
}
throw new ArithmeticException("long overflow");
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static int divideExact(int x, int y) {
int q = x / y;
if ((x & y & q) >= 0) {
return q;
}
throw new ArithmeticException("integer overflow");
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static long ceilDiv(long x, int y) {
return ceilDiv(x, (long) y);
}

@Stub(ref = @Ref("Ljava/lang/Math;"))
public static int ceilMod(int x, int y) {
final int r = x % y;
if ((x ^ y) >= 0 && r != 0) {
return r - y;
}
return r;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package xyz.wagyourtail.jvmdg.j18.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

public class J_L_StrictMath {

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long ceilDiv(long x, long y) {
return J_L_Math.ceilDiv(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long ceilDivExact(long x, long y) {
return J_L_Math.ceilDivExact(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long floorDivExact(long x, long y) {
return J_L_Math.floorDivExact(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long divideExact(long x, long y) {
return J_L_Math.divideExact(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static int ceilMod(long x, int y) {
return J_L_Math.ceilMod(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long ceilMod(long x, long y) {
return J_L_Math.ceilMod(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long unsignedMultiplyHigh(long x, long y) {
return J_L_Math.unsignedMultiplyHigh(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static int ceilDiv(int x, int y) {
return J_L_Math.ceilDiv(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static int floorDivExact(int x, int y) {
return J_L_Math.ceilDivExact(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static long ceilDiv(long x, int y) {
return J_L_Math.ceilDiv(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static int ceilMod(int x, int y) {
return J_L_Math.ceilMod(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static int ceilDivExact(int x, int y) {
return J_L_Math.ceilDivExact(x, y);
}

@Stub(ref = @Ref("Ljava/lang/StrictMath;"))
public static int divideExact(int x, int y) {
return J_L_Math.divideExact(x, y);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package xyz.wagyourtail.jvmdg.j18.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;

public class J_N_C_Charset {

@Stub(ref = @Ref("Ljava/nio/charset/Charset;"))
public static Charset forName(String name, Charset defaultCharset) {
try {
return Charset.forName(name);
} catch (UnsupportedCharsetException e) {
return defaultCharset;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.wagyourtail.jvmdg.j18.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Stub;

import java.time.Duration;

public class J_T_Duration {

@Stub
public static boolean isPositive(Duration duration) {
return !duration.isNegative() && !duration.isZero();
}

}
Loading

0 comments on commit 1814c15

Please sign in to comment.