global/local side effects startet

codetransformers canonicalized
CodeAnalyzer is now created by constructor


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1016 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 6eac2f2aea
commit fc38ca590f
  1. 87
      jode/jode/obfuscator/MethodIdentifier.java

@ -37,6 +37,7 @@ import jode.util.Map;
///import java.lang.ref.SoftReference; ///import java.lang.ref.SoftReference;
///#endif ///#endif
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.BitSet;
public class MethodIdentifier extends Identifier implements Opcodes { public class MethodIdentifier extends Identifier implements Opcodes {
ClassIdentifier clazz; ClassIdentifier clazz;
@ -44,21 +45,14 @@ public class MethodIdentifier extends Identifier implements Opcodes {
String name; String name;
String type; String type;
boolean globalSideEffects;
BitSet localSideEffects;
/** /**
* The code analyzer of this method, or null if there isn't any. * The code analyzer of this method, or null if there isn't any.
*/ */
CodeAnalyzer codeAnalyzer; CodeAnalyzer codeAnalyzer;
public CodeAnalyzer getCodeAnalyzer() {
if (codeAnalyzer != null)
return codeAnalyzer;
BytecodeInfo code = info.getBytecode();
if (code != null)
codeAnalyzer = new ConstantAnalyzer(code, this);
return codeAnalyzer;
}
public MethodIdentifier(ClassIdentifier clazz, MethodInfo info) { public MethodIdentifier(ClassIdentifier clazz, MethodInfo info) {
super(info.getName()); super(info.getName());
this.name = info.getName(); this.name = info.getName();
@ -72,20 +66,15 @@ public class MethodIdentifier extends Identifier implements Opcodes {
info.getBytecode().setLocalVariableTable(null); info.getBytecode().setLocalVariableTable(null);
if ((Main.stripping & Main.STRIP_LNT) != 0) if ((Main.stripping & Main.STRIP_LNT) != 0)
info.getBytecode().setLineNumberTable(null); info.getBytecode().setLineNumberTable(null);
codeAnalyzer = Main.createCodeAnalyzer();
} }
} }
public Iterator getChilds() { public Iterator getChilds() {
return Collections.EMPTY_LIST.iterator(); return Collections.EMPTY_LIST.iterator();
} }
public void applyPreserveRule(int preserveRule) {
if ((preserveRule & (info.getModifiers() ^ Modifier.PRIVATE)) != 0) {
setReachable();
setPreserved();
}
}
public void setSingleReachable() { public void setSingleReachable() {
super.setSingleReachable(); super.setSingleReachable();
Main.getClassBundle().analyzeIdentifier(this); Main.getClassBundle().analyzeIdentifier(this);
@ -112,8 +101,9 @@ public class MethodIdentifier extends Identifier implements Opcodes {
.reachableIdentifier(exceptions[i], false); .reachableIdentifier(exceptions[i], false);
} }
if (getCodeAnalyzer() != null) BytecodeInfo code = info.getBytecode();
getCodeAnalyzer().analyzeCode(); if (code != null)
codeAnalyzer.analyzeCode(this, code);
} }
public void readTable(Map table) { public void readTable(Map table) {
@ -153,6 +143,22 @@ public class MethodIdentifier extends Identifier implements Opcodes {
return "MethodIdentifier "+getFullName()+"."+getType(); return "MethodIdentifier "+getFullName()+"."+getType();
} }
public boolean hasGlobalSideEffects() {
return globalSideEffects;
}
public boolean getLocalSideEffects(int paramNr) {
return globalSideEffects || localSideEffects.get(paramNr);
}
public void setGlobalSideEffects() {
globalSideEffects = true;
}
public void setLocalSideEffects(int paramNr) {
localSideEffects.set(paramNr);
}
/** /**
* This method does the code transformation. This include * This method does the code transformation. This include
* <ul><li>new slot distribution for locals</li> * <ul><li>new slot distribution for locals</li>
@ -168,34 +174,21 @@ public class MethodIdentifier extends Identifier implements Opcodes {
wasTransformed = true; wasTransformed = true;
info.setName(getAlias()); info.setName(getAlias());
info.setType(Main.getClassBundle().getTypeAlias(type)); info.setType(Main.getClassBundle().getTypeAlias(type));
if (getCodeAnalyzer() != null) { if (codeAnalyzer != null) {
BytecodeInfo strippedBytecode = getCodeAnalyzer().stripCode(); BytecodeInfo bytecode = info.getBytecode();
// strippedBytecode.dumpCode(GlobalOptions.err); try {
codeAnalyzer.transformCode(bytecode);
/* XXX This should be in a if (Obfuscator.distributeLocals) */ for (Iterator i = Main.getCodeTransformers().iterator();
LocalOptimizer localOpt = new LocalOptimizer(this, i.hasNext(); ) {
strippedBytecode); CodeTransformer transformer = (CodeTransformer) i.next();
localOpt.calcLocalInfo(); transformer.transformCode(bytecode);
if ((GlobalOptions.debuggingFlags }
& GlobalOptions.DEBUG_LOCALS) != 0) { } catch (RuntimeException ex) {
GlobalOptions.err.println("Before Local Optimization: "); ex.printStackTrace(GlobalOptions.err);
localOpt.dumpLocals(); bytecode.dumpCode(GlobalOptions.err);
}
localOpt.stripLocals();
localOpt.distributeLocals();
if ((GlobalOptions.debuggingFlags
& GlobalOptions.DEBUG_LOCALS) != 0) {
GlobalOptions.err.println("After Local Optimization: ");
localOpt.dumpLocals();
} }
RemovePopAnalyzer remPop =
new RemovePopAnalyzer(strippedBytecode, this);
remPop.stripCode();
// strippedBytecode.dumpCode(GlobalOptions.err);
for (Instruction instr = strippedBytecode.getFirstInstr(); for (Instruction instr = bytecode.getFirstInstr();
instr != null; instr = instr.nextByAddr) { instr != null; instr = instr.nextByAddr) {
switch (instr.opcode) { switch (instr.opcode) {
case opc_invokespecial: case opc_invokespecial:
@ -226,7 +219,7 @@ public class MethodIdentifier extends Identifier implements Opcodes {
} }
} }
Handler[] handlers = strippedBytecode.getExceptionHandlers(); Handler[] handlers = bytecode.getExceptionHandlers();
for (int i=0; i< handlers.length; i++) { for (int i=0; i< handlers.length; i++) {
if (handlers[i].type != null) { if (handlers[i].type != null) {
ClassIdentifier ci = Main.getClassBundle() ClassIdentifier ci = Main.getClassBundle()
@ -235,7 +228,7 @@ public class MethodIdentifier extends Identifier implements Opcodes {
handlers[i].type = ci.getFullAlias(); handlers[i].type = ci.getFullAlias();
} }
} }
info.setBytecode(strippedBytecode); info.setBytecode(bytecode);
} }
} }
} }

Loading…
Cancel
Save