Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java
#	src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java
  • Loading branch information
shedaniel committed Sep 23, 2023
2 parents 2d10d61 + f1b8540 commit a70d7e5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2018, 2022, FabricMC
* Copyright (c) 2018, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -178,6 +179,7 @@ public AnnotationVisitor createAnnotationRemapper(String descriptor, AnnotationV
}

private static class AsmMethodRemapper extends MethodRemapper {
private final TinyRemapper tr;
AsmMethodRemapper(MethodVisitor methodVisitor,
AsmRemapper remapper,
String owner,
Expand All @@ -196,6 +198,7 @@ private static class AsmMethodRemapper extends MethodRemapper {
this.renameInvalidLocals = renameInvalidLocals;
this.invalidLvNamePattern = invalidLvNamePattern;
this.inferNameFromSameLvIndex = inferNameFromSameLvIndex;
this.tr = remapper.tr;
}

@Override
Expand Down Expand Up @@ -259,7 +262,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String descri

@Override
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
Handle implemented = getLambdaImplementedMethod((AsmRemapper) remapper, name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
Handle implemented = getLambdaImplementedMethod((AsmRemapper) remapper, name, descriptor, bootstrapMethodHandle, tr.knownIndyBsm, bootstrapMethodArguments);

if (implemented != null) {
name = remapper.mapMethodName(implemented.getOwner(), implemented.getName(), implemented.getDesc());
Expand All @@ -277,12 +280,11 @@ public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootst
bootstrapMethodArguments);
}

private static Handle getLambdaImplementedMethod(AsmRemapper remapper, String name, String desc, Handle bsm, Object... bsmArgs) {
private static Handle getLambdaImplementedMethod(AsmRemapper remapper, String name, String desc, Handle bsm, Set<String> knownIndyBsm, Object... bsmArgs) {
if (isJavaLambdaMetafactory(bsm)) {
assert desc.endsWith(";");
return new Handle(Opcodes.H_INVOKEINTERFACE, desc.substring(desc.lastIndexOf(')') + 2, desc.length() - 1), name, ((Type) bsmArgs[0]).getDescriptor(), true);
} else if (bsm.getOwner().equals("java/lang/invoke/StringConcatFactory")
|| bsm.getOwner().equals("java/lang/runtime/ObjectMethods")) {
} else if (knownIndyBsm.contains(bsm.getOwner())) {
return null;
} else {
if (remapper.tr.logUnknownInvokeDynamic) {
Expand Down
35 changes: 32 additions & 3 deletions src/main/java/net/fabricmc/tinyremapper/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2016, 2021, FabricMC
* Copyright (c) 2016, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -20,8 +20,10 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -45,6 +47,8 @@ public static void main(String[] rawArgs) {
boolean removeFrames = false;
Set<String> forcePropagation = Collections.emptySet();
File forcePropagationFile = null;
Set<String> knownIndyBsm = new HashSet<>();
File knownIndyBsmFile = null;
boolean ignoreConflicts = false;
boolean checkPackageAccess = false;
boolean fixPackageAccess = false;
Expand All @@ -71,6 +75,8 @@ public static void main(String[] rawArgs) {
case "forcepropagation":
forcePropagationFile = new File(arg.substring(valueSepPos + 1));
break;
case "knownindybsm":
knownIndyBsmFile = new File(arg.substring(valueSepPos + 1));
case "propagateprivate":
propagatePrivate = true;
break;
Expand Down Expand Up @@ -186,7 +192,7 @@ public static void main(String[] rawArgs) {
System.exit(1);
}

try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(forcePropagationFile), StandardCharsets.UTF_8))) {
String line;

while ((line = reader.readLine()) != null) {
Expand All @@ -202,12 +208,35 @@ public static void main(String[] rawArgs) {
}
}

if (knownIndyBsmFile != null) {
if (!knownIndyBsmFile.canRead()) {
System.out.println("Can't read knownIndyBsm file "+knownIndyBsmFile+".");
System.exit(1);
}

try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(knownIndyBsmFile), StandardCharsets.UTF_8))) {
String line;

while ((line = reader.readLine()) != null) {
line = line.trim();

if (line.isEmpty() || line.charAt(0) == '#') continue;

knownIndyBsm.add(line);
}
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}

long startTime = System.nanoTime();

TinyRemapper.Builder builder = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.ignoreFieldDesc(ignoreFieldDesc)
.withForcedPropagation(forcePropagation)
.withKnownIndyBsm(knownIndyBsm)
.propagatePrivate(propagatePrivate)
.propagateBridges(propagateBridges)
.removeFrames(removeFrames)
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public Builder withForcedPropagation(Set<String> entries) {
return this;
}

public Builder withKnownIndyBsm(Set<String> entries) {
knownIndyBsm.addAll(entries);
return this;
}

public Builder propagatePrivate(boolean value) {
propagatePrivate = value;
return this;
Expand Down Expand Up @@ -238,7 +243,7 @@ public Builder logger(Consumer<String> value) {
public TinyRemapper build() {
TinyRemapper remapper = new TinyRemapper(mappingProviders, ignoreFieldDesc, threadCount,
keepInputData,
forcePropagation, propagatePrivate,
forcePropagation, knownIndyBsm, propagatePrivate,
propagateBridges, propagateRecordComponents,
removeFrames, ignoreConflicts, resolveMissing, checkPackageAccess || fixPackageAccess, fixPackageAccess,
rebuildSourceFilenames, skipLocalMapping, renameInvalidLocals, invalidLvNamePattern, inferNameFromSameLvIndex,
Expand All @@ -253,6 +258,7 @@ public TinyRemapper build() {
private boolean ignoreFieldDesc;
private int threadCount;
private final Set<String> forcePropagation = new HashSet<>();
private final Set<String> knownIndyBsm = new HashSet<>();
private boolean keepInputData = false;
private boolean propagatePrivate = false;
private LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED;
Expand Down Expand Up @@ -298,7 +304,7 @@ public interface ApplyVisitorProvider {
private TinyRemapper(Set<IMappingProvider> mappingProviders, boolean ignoreFieldDesc,
int threadCount,
boolean keepInputData,
Set<String> forcePropagation, boolean propagatePrivate,
Set<String> forcePropagation, Set<String> knownIndyBsm, boolean propagatePrivate,
LinkedMethodPropagation propagateBridges, LinkedMethodPropagation propagateRecordComponents,
boolean removeFrames,
boolean ignoreConflicts,
Expand All @@ -322,6 +328,7 @@ private TinyRemapper(Set<IMappingProvider> mappingProviders, boolean ignoreField
this.keepInputData = keepInputData;
this.threadPool = Executors.newFixedThreadPool(this.threadCount);
this.forcePropagation = forcePropagation;
this.knownIndyBsm = knownIndyBsm;
this.propagatePrivate = propagatePrivate;
this.propagateBridges = propagateBridges;
this.propagateRecordComponents = propagateRecordComponents;
Expand All @@ -345,6 +352,9 @@ private TinyRemapper(Set<IMappingProvider> mappingProviders, boolean ignoreField
this.postApplyVisitors = postApplyVisitors;
this.extraRemapper = extraRemapper;
this.logger = logger;

this.knownIndyBsm.add("java/lang/invoke/StringConcatFactory");
this.knownIndyBsm.add("java/lang/runtime/ObjectMethods");
}

public static Builder newRemapper() {
Expand Down Expand Up @@ -1596,6 +1606,7 @@ public boolean isMappingsDirty() {

private final boolean keepInputData;
final Set<String> forcePropagation;
final Set<String> knownIndyBsm;
final boolean propagatePrivate;
final LinkedMethodPropagation propagateBridges;
final LinkedMethodPropagation propagateRecordComponents;
Expand Down

0 comments on commit a70d7e5

Please sign in to comment.