From 44767a9735ee06d0a81ecf05ffb5929c59ef8272 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 15 Nov 2015 11:59:08 -0500 Subject: [PATCH] Add flag for graph building, which uses too much memory. --- .../runelite/deob/execution/Execution.java | 13 ++++++++++++- .../deob/execution/MethodContext.java | 19 +++++++++++++++++-- .../runelite/deob/execution/FrameTest.java | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 7b670ca416..0d95a4dd67 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -27,6 +27,7 @@ public class Execution private Encryption encryption; public MultiValueMap contexts = new MultiValueMap<>(); private Map methodContexts = new HashMap<>(); + private boolean buildGraph; public Execution(ClassGroup group) { @@ -139,8 +140,18 @@ public class Execution if (c != null) return c; - c = new MethodContext(); + c = new MethodContext(this); methodContexts.put(m, c); return c; } + + public boolean isBuildGraph() + { + return buildGraph; + } + + public void setBuildGraph(boolean buildGraph) + { + this.buildGraph = buildGraph; + } } diff --git a/src/main/java/net/runelite/deob/execution/MethodContext.java b/src/main/java/net/runelite/deob/execution/MethodContext.java index d9f4957bd6..d91cbdeccc 100644 --- a/src/main/java/net/runelite/deob/execution/MethodContext.java +++ b/src/main/java/net/runelite/deob/execution/MethodContext.java @@ -12,6 +12,7 @@ import java.util.Objects; import net.runelite.deob.Method; import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction; +import net.runelite.deob.attributes.code.instructions.InvokeStatic; import net.runelite.deob.util.IdGen; import org.apache.commons.collections4.map.MultiValueMap; @@ -67,11 +68,17 @@ class MIKey public class MethodContext { + private Execution execution; private MultiValueMap visited = new MultiValueMap<>(); private IdGen ids = new IdGen(); private Map idMap = new HashMap<>(); private Map insMap = new HashMap<>(); private Graph graph = new SparseDirectedGraph(); + + public MethodContext(Execution execution) + { + this.execution = execution; + } public Map getIdMap() { @@ -85,11 +92,13 @@ public class MethodContext protected boolean hasJumped(List fromm, InstructionContext from, Instruction to) { - Collection i = visited.getCollection(new MIKey(fromm, from)); + // with this true, there are so many frames I can't run a full execution without oom. + MIKey key = execution.isBuildGraph() ? new MIKey(fromm, from) : new MIKey(null, from); + Collection i = visited.getCollection(key); if (i != null && i.contains(to)) return true; - visited.put(new MIKey(fromm, from), to); + visited.put(key, to); return false; } @@ -110,8 +119,14 @@ public class MethodContext protected void buildGraph(Frame frame, Instruction i) { + if (!execution.isBuildGraph()) + return; + if (i instanceof InvokeInstruction) { +// if (i instanceof InvokeStatic) +// return; + InvokeInstruction ii = (InvokeInstruction) i; List methods = ii.getMethods(); diff --git a/src/test/java/net/runelite/deob/execution/FrameTest.java b/src/test/java/net/runelite/deob/execution/FrameTest.java index d44c7f6b43..acbe88e663 100644 --- a/src/test/java/net/runelite/deob/execution/FrameTest.java +++ b/src/test/java/net/runelite/deob/execution/FrameTest.java @@ -70,6 +70,7 @@ public class FrameTest ins.addInstruction(i); Execution e = new Execution(group); + e.setBuildGraph(true); e.populateInitialMethods(); e.run(); @@ -123,6 +124,7 @@ public class FrameTest ins.addInstruction(i); Execution e = new Execution(group); + e.setBuildGraph(true); e.populateInitialMethods(); e.run();