System",
"currentTimeMillis", Type.LONG, Type.NO_ARGS,
Constants.INVOKESTATIC));
ilist.append(InstructionFactory.createLoad(Type.LONG, slot));
ilist.append(InstructionConstants.LSUB);
ilist.append(ifact.createInvoke("java.io.PrintStream", "print",
Type.VOID, new Type[] { Type.LONG }, Constants.INVOKEVIRTUAL));
ilist.append(new PUSH(pgen, " ms."));
ilist.append(ifact.createInvoke("java.io.PrintStream", "println",
Type.VOID, new Type[] { Type.STRING }, Constants.INVOKEVIRTUAL));
伏撹阻柴扮?連旗鷹朔?藻公賠汽 7 議祥頁隠贋淫廾議圭隈議距喘潤惚峙?泌惚嗤議三 ??隼朔潤崩更秀議淫廾匂圭隈。恷朔宸何蛍膚式叱倖化帶。距喘 stripAttributes(true) 峪頁御盆 BCEL 音斤更秀議圭隈伏撹距編佚連?遇 setMaxStack() 才 setMaxLocals() 距喘 柴麻旺譜崔圭隈議均媚聞喘佚連。頼撹阻宸匯化朔?祥辛參糞縞伏撹圭隈議恷嶮井云?旺繍 万紗秘欺窃嶄。
賠汽 7. 頼撹淫廾匂
// return result from wrapped method call
if (result != Type.VOID) {
ilist.append(InstructionFactory.createLoad(result, slot+2));
}
ilist.append(InstructionFactory.createReturn(result));
// finalize the constructed method
wrapgen.stripAttributes(true);
wrapgen.setMaxStack();
wrapgen.setMaxLocals();
cgen.addMethod(wrapgen.getMethod());
ilist.dispose();
頼屁議旗鷹
賠汽 8 ?幣阻頼屁議旗鷹?不裏個延阻匯和鯉塀參癖栽?幣錐業??淫凄參窃猟周議兆 忖葎歌方議 main() 圭隈才勣廬算議圭隈?
賠汽 8. 頼屁議廬算旗鷹
public class BCELTiming
{
private static void addWrapper(ClassGen cgen, Method method) {
// set up the construction tools
InstructionFactory ifact = new InstructionFactory(cgen);
InstructionList ilist = new InstructionList();
ConstantPoolGen pgen = cgen.getConstantPool();
String cname = cgen.getClassName();
MethodGen wrapgen = new MethodGen(method, cname, pgen);
wrapgen.setInstructionList(ilist);
// rename a copy of the original method
MethodGen methgen = new MethodGen(method, cname, pgen);
cgen.removeMethod(method);
String iname = methgen.getName() + "$impl";
methgen.setName(iname);
cgen.addMethod(methgen.getMethod());
Type result = methgen.getReturnType();
// compute the size of the calling parameters
Type[] types = methgen.getArgumentTypes();
int slot = methgen.isStatic() ? 0 : 1;
for (int i = 0; i < types.length; i++) {
slot += types[i].getSize();
}
// save time prior to invocation
ilist.append(ifact.createInvoke("java.lang.System",
"currentTimeMillis", Type.LONG, Type.NO_ARGS,
Constants.INVOKESTATIC));
ilist.append(InstructionFactory.
createStore(Type.LONG, slot));
// call the wrapped method
int offset = 0;
|