Skip to content

Commit

Permalink
Large decompliation slow down (I'm a bozo)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolMineman committed Oct 28, 2021
1 parent 65edde8 commit a10d39f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion brachyura/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.coolcrabs</groupId>
<artifactId>brachyura</artifactId>
<version>0.12</version>
<version>0.13</version>

<properties>
<java.version>1.8</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.benf.cfr.reader.api.ClassFileSource;
import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair;
import org.jetbrains.annotations.Nullable;
import org.tinylog.Logger;

import io.github.coolcrabs.brachyura.util.FileSystemUtil;
import io.github.coolcrabs.brachyura.util.JvmUtil;
import io.github.coolcrabs.brachyura.util.PathUtil;
import io.github.coolcrabs.brachyura.util.StreamUtil;
import io.github.coolcrabs.brachyura.util.Util;

class BrachyuraCfrClassFileSource implements ClassFileSource, Closeable {
private final Map<String, Path> allClasses = new HashMap<>();
private final ConcurrentHashMap<String, byte[]> classmap = new ConcurrentHashMap<>();
private final List<FileSystem> toClose = new ArrayList<>();

public BrachyuraCfrClassFileSource(Path mainJar, List<Path> classpath, List<String> mainClassesOut) throws IOException {
Expand All @@ -51,10 +55,11 @@ private void loadJar(FileSystem fileSystem, @Nullable List<String> classesOut) t
Files.walkFileTree(fileSystem.getPath("/"), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (file.toString().endsWith(".class")) {
allClasses.put(file.toString(), file);
String path = file.toString().substring(1);
if (path.endsWith(".class")) {
allClasses.put(path, file);
if (classesOut != null) {
classesOut.add(file.toString());
classesOut.add(path);
}
}
return FileVisitResult.CONTINUE;
Expand All @@ -74,7 +79,7 @@ private void loadRtJ8() throws IOException {
String[] jars = System.getProperty("sun.boot.class.path").split(File.pathSeparator);
for (String jar : jars) {
Path path = Paths.get(jar);
if (Files.exists(path)) { // ??? whatever sunrsasign.jar is claims to be on bootstrap classpath but doesn't exikst
if (Files.exists(path)) { // ??? whatever sunrsasign.jar is claims to be on bootstrap classpath but doesn't exist
FileSystem fs;
try {
fs = FileSystems.getFileSystem(new URI("jar:file", null, path.toUri().getPath(), ""));
Expand Down Expand Up @@ -118,15 +123,24 @@ public String getPossiblyRenamedPath(String path) {

@Override
public Pair<byte[], String> getClassFileContent(String path) throws IOException {
Path path2 = allClasses.get(path);
if (path2 != null) {
try (InputStream inputStream = PathUtil.inputStream(path2)) {
return new Pair<>(StreamUtil.readFullyAsBytes(inputStream), path);
byte[] content = classmap.computeIfAbsent(path, p -> {
try {
Path path2 = allClasses.get(path);
if (path2 != null) {
try (InputStream inputStream = PathUtil.inputStream(path2)) {
return StreamUtil.readFullyAsBytes(inputStream);
}
} else {
Logger.warn("Unable to find " + path);
return null;
}
} catch (Exception e) {
throw Util.sneak(e);
}
} else {
return null;
}
});
return new Pair<>(content, path);
}


@Override
public void close() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.junit.jupiter.api.Test;

import io.github.coolcrabs.brachyura.decompiler.BrachyuraDecompiler;
import io.github.coolcrabs.brachyura.maven.MavenId;
import io.github.coolcrabs.brachyura.util.JvmUtil;
import io.github.coolcrabs.brachyura.util.PathUtil;
Expand Down Expand Up @@ -54,10 +53,10 @@ public void getModDependencies(ModDependencyCollector d) {
d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-game-rule-api-v1", "1.0.7+cbda931888"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE, ModDependencyFlag.JIJ);
};

@Override
public BrachyuraDecompiler decompiler() {
return null;
};
// @Override
// public BrachyuraDecompiler decompiler() {
// return null;
// };
};

@Test
Expand Down

0 comments on commit a10d39f

Please sign in to comment.