Including mapper map stuff in

This commit is contained in:
Adam
2016-02-12 12:03:49 -05:00
parent 4021e3d02f
commit d4b148f72a
3 changed files with 92 additions and 25 deletions

View File

@@ -87,7 +87,8 @@ public class MappingExecutorUtil
frame2.other = frame;
ParallellMappingExecutor parallel = new ParallellMappingExecutor(e, e2);
ParallelExecutorMapping mappings = new ParallelExecutorMapping();
ParallelExecutorMapping mappings = new ParallelExecutorMapping(m1.getMethods().getClassFile().getGroup(),
m2.getMethods().getClassFile().getGroup());
mappings.m1 = m1;
mappings.m2 = m2;

View File

@@ -4,16 +4,27 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.Field;
import net.runelite.deob.Method;
public class ParallelExecutorMapping
{
private ClassGroup group, group2;
private Map<Object, Object> map = new HashMap<>();
private List<Object> order = new ArrayList<>();
public Method m1, m2;
public ParallelExecutorMapping(ClassGroup group, ClassGroup group2)
{
this.group = group;
this.group2 = group2;
assert group != group2;
}
public void merge(ParallelExecutorMapping other)
{
assert this != other;
map.putAll(other.map); // is this right?
}
@@ -24,6 +35,9 @@ public class ParallelExecutorMapping
if (map.containsKey(one))
return;
belongs(one, group);
belongs(two, group2);
map.put(one, two);
order.add(one);
}
@@ -39,4 +53,20 @@ public class ParallelExecutorMapping
}
public List<Object> getOrder() { return order; }
private void belongs(Object o, ClassGroup to)
{
if (o instanceof Field)
{
Field f = (Field) o;
assert f.getFields().getClassFile().getGroup() == to;
}
else if (o instanceof Method)
{
Method m = (Method) o;
assert m.getMethods().getClassFile().getGroup() == to;
}
else
assert false;
}
}

View File

@@ -123,11 +123,11 @@ public class MapStaticTest
List<ParallelExecutorMapping> pmes = new ArrayList<>();
map(all, pmes, m1, m2);
ParallelExecutorMapping finalm = new ParallelExecutorMapping();
ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2);
for (ParallelExecutorMapping pme : pmes)
finalm.merge(pme);
summary(finalm);
//summary(finalm);
}
//@Test
@@ -149,7 +149,7 @@ public class MapStaticTest
}
}
private void summary(ParallelExecutorMapping finalm)
private void summary(ParallelExecutorMapping finalm, ClassGroup in)
{
int fields = 0, staticMethod = 0, method = 0, total = 0;
for (Entry<Object, Object> e : finalm.getMap().entrySet())
@@ -158,10 +158,16 @@ public class MapStaticTest
Object o = e.getKey();
if (o instanceof Field)
{
++fields;
Field f = (Field) o;
assert f.getFields().getClassFile().getGroup() == in;
}
else if (o instanceof Method)
{
Method m = (Method) o;
assert m.getMethods().getClassFile().getGroup() == in;
if (m.isStatic())
++staticMethod;
@@ -216,12 +222,21 @@ public class MapStaticTest
}
}
ParallelExecutorMapping finalm = new ParallelExecutorMapping();
ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2);
for (ParallelExecutorMapping pme : pmes)
finalm.merge(pme);
summary(finalm);
print(group1);
finalm.merge(testStaticMapperMap(group1, group2));
finalm.merge(testMapperMap(group1, group2));
summary(finalm, group1);
String sg1 = print(group1),
sg2 = print(group2);
System.out.println("GROUP 1 " + sg1);
System.out.println("GROUP 2 " + sg2);
// System.out.println("db step " + ParallellMappingExecutor.doubleStep.size());
//
// for (Method m : group1.findClass("client").getMethods().getMethods())
@@ -237,10 +252,10 @@ public class MapStaticTest
}
//@Test
public void testMapperMap() throws IOException
public ParallelExecutorMapping testMapperMap(ClassGroup one, ClassGroup two) throws IOException
{
ClassGroup one = JarUtil.loadJar(new File(JAR1));
ClassGroup two = JarUtil.loadJar(new File(JAR2));
// ClassGroup one = JarUtil.loadJar(new File(JAR1));
// ClassGroup two = JarUtil.loadJar(new File(JAR2));
List<ParallelExecutorMapping> pmes = new ArrayList<>();
for (int i = 0; i < 250; ++i)
@@ -261,35 +276,56 @@ public class MapStaticTest
map(all, pmes, e.getKey(), e.getValue());
}
}
ParallelExecutorMapping finalm = new ParallelExecutorMapping();
ParallelExecutorMapping finalm = new ParallelExecutorMapping(one, two);
for (ParallelExecutorMapping pme : pmes)
finalm.merge(pme);
summary(finalm);
print(one);
return finalm;
// summary(finalm);
// print(one);
}
@Test
public void testStaticMapperMap() throws IOException
//@Test
public ParallelExecutorMapping testStaticMapperMap(ClassGroup one, ClassGroup two) throws IOException
{
ClassGroup one = JarUtil.loadJar(new File(JAR1));
ClassGroup two = JarUtil.loadJar(new File(JAR2));
// ClassGroup one = JarUtil.loadJar(new File(JAR1));
// ClassGroup two = JarUtil.loadJar(new File(JAR2));
StaticMethodSignatureMapper smsm = new StaticMethodSignatureMapper();
smsm.map(one, two);
List<ParallelExecutorMapping> pmes = new ArrayList<>();
for (Method m : smsm.getMap().keySet())
{
Collection<Method> methods = smsm.getMap().get(m);
if (methods.size() == 1)
//if (methods.size() >= 1)
{
Method other = methods.stream().findFirst().get();
ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other);
for (Method other : methods)
{
ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other);
if (pme.getMap().isEmpty())
continue;
System.out.println(m + " " + other + " " + pme.getMap().size());
// HashMap<Object, Object> all = new HashMap();
// map(all, pmes, m, other);
pme.map(m, other);
pmes.add(pme);
//System.out.println(m + " " + other + " " + pme.getMap().size());
}
}
}
ParallelExecutorMapping finalm = new ParallelExecutorMapping(one, two);
for (ParallelExecutorMapping pme : pmes)
finalm.merge(pme);
return finalm;
// summary(finalm);
// print(one);
}
public List<Method> getInitialMethods(ClassGroup group)
@@ -378,7 +414,7 @@ public class MapStaticTest
}
}
private void print(ClassGroup cg)
private String print(ClassGroup cg)
{
int methods = 0, fields = 0, classes = 0;
for (ClassFile cf : cg.getClasses())
@@ -388,7 +424,7 @@ public class MapStaticTest
fields += cf.getFields().getFields().size();
}
int total = methods + fields;
System.out.println("Goal; total m/f: " + total + ", " + methods + " methods, " + fields + " fields");
return "total methods/fields: " + total + ", " + methods + " methods, " + fields + " fields";
}
@Test
@@ -396,6 +432,6 @@ public class MapStaticTest
{
ClassGroup group1 = JarUtil.loadJar(new File(JAR1));
//ClassGroup group2 = JarUtil.loadJar(new File(JAR2));
print(group1);
//print(group1);
}
}