Synchronized JarUtil ClassWriters

This should be re-evaluated, it's most likely not needed and it will slow down multi-pane decompilation

An alternative solution is generating the ClassNode List once, then storing it in a cache that can be quickly saved to disk. If a new file gets added regenerate the cache.
This commit is contained in:
Konloch 2021-07-04 01:56:25 -07:00
parent 854c4d622c
commit c0eb9e944e

View file

@ -17,7 +17,6 @@ import java.util.zip.ZipInputStream;
import me.konloch.kontainer.io.DiskWriter;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
@ -51,7 +50,9 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
* @since 09/26/2011
*/
public class JarUtils {
public class JarUtils
{
public static Object LOCK = new Object();
/**
* Loads the classes and resources from the input jar file
@ -245,8 +246,11 @@ public class JarUtils {
* @return the ClassNode instance
*/
public static ClassNode getNode(final byte[] bytez) {
synchronized (LOCK)
{
return ASMUtil.getClassNode(bytez);
}
}
/**
* Saves as jar with manifest
@ -296,16 +300,21 @@ public class JarUtils {
* @param path the exact jar output path
*/
public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String path) {
try {
synchronized (LOCK)
{
try
{
JarOutputStream out = new JarOutputStream(new FileOutputStream(path));
ArrayList<String> noDupe = new ArrayList<>();
for (ClassNode cn : nodeList) {
for (ClassNode cn : nodeList)
{
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
String name = cn.name + ".class";
if (!noDupe.contains(name)) {
if (!noDupe.contains(name))
{
noDupe.add(name);
out.putNextEntry(new ZipEntry(name));
out.write(cw.toByteArray());
@ -315,10 +324,13 @@ public class JarUtils {
noDupe.clear();
out.close();
} catch (IOException e) {
}
catch (IOException e)
{
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
}
/**
* Saves a jar without the manifest