public CodeAnalyzer(CodeAttribute ca) { codeAttr = ca; constPool = ca.getConstPool(); }
public CodeAnalyzer(CodeAttribute ca) { codeAttr = ca; constPool = ca.getConstPool(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }
/** * Copies code. */ private byte[] copyCode(ConstPool destCp, Map classnames, ExceptionTable etable, CodeAttribute destCa) throws BadBytecode { int len = getCodeLength(); byte[] newCode = new byte[len]; destCa.info = newCode; LdcEntry ldc = copyCode(this.info, 0, len, this.getConstPool(), newCode, destCp, classnames); return LdcEntry.doit(newCode, ldc, etable, destCa); }
/** * Copies code. */ private byte[] copyCode(ConstPool destCp, Map<String,String> classnames, ExceptionTable etable, CodeAttribute destCa) throws BadBytecode { int len = getCodeLength(); byte[] newCode = new byte[len]; destCa.info = newCode; LdcEntry ldc = copyCode(this.info, 0, len, this.getConstPool(), newCode, destCp, classnames); return LdcEntry.doit(newCode, ldc, etable, destCa); }
public int computeMaxStack() throws BadBytecode { /* d = stack[i] * d == 0: not visited * d > 0: the depth is d - 1 after executing the bytecode at i. * d < 0: not visited. the initial depth (before execution) is 1 - d. */ CodeIterator ci = codeAttr.iterator(); int length = ci.getCodeLength(); int[] stack = new int[length]; constPool = codeAttr.getConstPool(); initStack(stack, codeAttr); boolean repeat; do { repeat = false; for (int i = 0; i < length; ++i) if (stack[i] < 0) { repeat = true; visitBytecode(ci, stack, i); } } while (repeat); int maxStack = 1; for (int i = 0; i < length; ++i) if (stack[i] > maxStack) maxStack = stack[i]; return maxStack - 1; // the base is 1. }
private int skipSuperConstructor0(int skipThis) throws BadBytecode { begin(); ConstPool cp = codeAttr.getConstPool(); String thisClassName = codeAttr.getDeclaringClass(); int nested = 0; while (hasNext()) { int index = next(); int c = byteAt(index); if (c == NEW) ++nested; else if (c == INVOKESPECIAL) { int mref = ByteArray.readU16bit(bytecode, index + 1); if (cp.getMethodrefName(mref).equals(MethodInfo.nameInit)) if (--nested < 0) { if (skipThis < 0) return index; String cname = cp.getMethodrefClassName(mref); if (cname.equals(thisClassName) == (skipThis > 0)) return index; else break; } } } begin(); return -1; }
public int computeMaxStack() throws BadBytecode { /* d = stack[i] * d == 0: not visited * d > 0: the depth is d - 1 after executing the bytecode at i. * d < 0: not visited. the initial depth (before execution) is 1 - d. */ CodeIterator ci = codeAttr.iterator(); int length = ci.getCodeLength(); int[] stack = new int[length]; constPool = codeAttr.getConstPool(); initStack(stack, codeAttr); boolean repeat; do { repeat = false; for (int i = 0; i < length; ++i) if (stack[i] < 0) { repeat = true; visitBytecode(ci, stack, i); } } while (repeat); int maxStack = 1; for (int i = 0; i < length; ++i) if (stack[i] > maxStack) maxStack = stack[i]; return maxStack - 1; // the base is 1. }
private int skipSuperConstructor0(int skipThis) throws BadBytecode { begin(); ConstPool cp = codeAttr.getConstPool(); String thisClassName = codeAttr.getDeclaringClass(); int nested = 0; while (hasNext()) { int index = next(); int c = byteAt(index); if (c == NEW) ++nested; else if (c == INVOKESPECIAL) { int mref = ByteArray.readU16bit(bytecode, index + 1); if (cp.getMethodrefName(mref).equals(MethodInfo.nameInit)) if (--nested < 0) { if (skipThis < 0) return index; String cname = cp.getMethodrefClassName(mref); if (cname.equals(thisClassName) == (skipThis > 0)) return index; break; } } } begin(); return -1; }
/** * Returns true if the constructor (or static initializer) * is the default one. This method returns true if the constructor * takes some arguments but it does not perform anything except * calling <code>super()</code> (the no-argument constructor of * the super class). */ public boolean isEmpty() { CodeAttribute ca = getMethodInfo2().getCodeAttribute(); if (ca == null) return false; // native or abstract?? // they are not allowed, though. ConstPool cp = ca.getConstPool(); CodeIterator it = ca.iterator(); try { int pos, desc; int op0 = it.byteAt(it.next()); return op0 == Opcode.RETURN // empty static initializer || (op0 == Opcode.ALOAD_0 && it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL && (desc = cp.isConstructor(getSuperclassName(), it.u16bitAt(pos + 1))) != 0 && "()V".equals(cp.getUtf8Info(desc)) && it.byteAt(it.next()) == Opcode.RETURN && !it.hasNext()); } catch (BadBytecode e) {} return false; }
/** * Returns true if the constructor (or static initializer) * is the default one. This method returns true if the constructor * takes some arguments but it does not perform anything except * calling <code>super()</code> (the no-argument constructor of * the super class). */ @Override public boolean isEmpty() { CodeAttribute ca = getMethodInfo2().getCodeAttribute(); if (ca == null) return false; // native or abstract?? // they are not allowed, though. ConstPool cp = ca.getConstPool(); CodeIterator it = ca.iterator(); try { int pos, desc; int op0 = it.byteAt(it.next()); return op0 == Opcode.RETURN // empty static initializer || (op0 == Opcode.ALOAD_0 && it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL && (desc = cp.isConstructor(getSuperclassName(), it.u16bitAt(pos + 1))) != 0 && "()V".equals(cp.getUtf8Info(desc)) && it.byteAt(it.next()) == Opcode.RETURN && !it.hasNext()); } catch (BadBytecode e) {} return false; }
if (pos >= 0) { int mref = iterator.u16bitAt(pos + 1); String desc = ca.getConstPool().getMethodrefType(mref); int num = Descriptor.numOfParameters(desc) + 1; if (num > 3)
if (pos >= 0) { int mref = iterator.u16bitAt(pos + 1); String desc = ca.getConstPool().getMethodrefType(mref); int num = Descriptor.numOfParameters(desc) + 1; if (num > 3)
public CodeAnalyzer(CodeAttribute ca) { codeAttr = ca; constPool = ca.getConstPool(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }
/** * Returns the name of the class declaring the method including * this code attribute. */ public String getDeclaringClass() { ConstPool cp = getConstPool(); return cp.getClassName(); }