本文整理汇总了Java中scouter.javassist.bytecode.Bytecode.addIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Bytecode.addIndex方法的具体用法?Java Bytecode.addIndex怎么用?Java Bytecode.addIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scouter.javassist.bytecode.Bytecode
的用法示例。
在下文中一共展示了Bytecode.addIndex方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doit
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError
{
if (args != null && !gen.isParamListName(args))
throw new CompileError(Javac.proceedName
+ "() cannot take a parameter for field reading");
int stack;
if (isStatic(opcode))
stack = 0;
else {
stack = -1;
bytecode.addAload(targetVar);
}
if (fieldType instanceof CtPrimitiveType)
stack += ((CtPrimitiveType)fieldType).getDataSize();
else
++stack;
bytecode.add(opcode);
bytecode.addIndex(index);
bytecode.growStack(stack);
gen.setType(fieldType);
}
示例2: doit
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError
{
int num = gen.getMethodArgsLength(args);
if (num != dimension)
throw new CompileError(Javac.proceedName
+ "() with a wrong number of parameters");
gen.atMethodArgs(args, new int[num],
new int[num], new String[num]);
bytecode.addOpcode(opcode);
if (opcode == Opcode.ANEWARRAY)
bytecode.addIndex(index);
else if (opcode == Opcode.NEWARRAY)
bytecode.add(index);
else /* if (opcode == Opcode.MULTIANEWARRAY) */ {
bytecode.addIndex(index);
bytecode.add(dimension);
bytecode.growStack(1 - dimension);
}
gen.setType(arrayType);
}
示例3: addFinally
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
* Adds a finally clause for earch return statement.
*/
private void addFinally(ArrayList returnList, Stmnt finallyBlock)
throws CompileError
{
Bytecode bc = bytecode;
int n = returnList.size();
for (int i = 0; i < n; ++i) {
final int[] ret = (int[])returnList.get(i);
int pc = ret[0];
bc.write16bit(pc, bc.currentPc() - pc + 1);
ReturnHook hook = new JsrHook2(this, ret);
finallyBlock.accept(this);
hook.remove(this);
if (!hasReturned) {
bc.addOpcode(Opcode.GOTO);
bc.addIndex(pc + 3 - bc.currentPc());
}
}
}
示例4: makeConstructor
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static MethodInfo makeConstructor(String thisClassName, Constructor cons,
ConstPool cp, Class superClass, boolean doHandlerInit) {
String desc = RuntimeSupport.makeDescriptor(cons.getParameterTypes(),
Void.TYPE);
MethodInfo minfo = new MethodInfo(cp, "<init>", desc);
minfo.setAccessFlags(Modifier.PUBLIC); // cons.getModifiers() & ~Modifier.NATIVE
setThrows(minfo, cp, cons.getExceptionTypes());
Bytecode code = new Bytecode(cp, 0, 0);
// legacy: if we are not using caching then we initialise the instance's handler
// from the class's static default interceptor and skip the next few instructions if
// it is non-null
if (doHandlerInit) {
code.addAload(0);
code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
code.addOpcode(Opcode.IFNONNULL);
code.addIndex(10);
}
// if caching is enabled then we don't have a handler to initialise so this else branch will install
// the handler located in the static field of class RuntimeSupport.
code.addAload(0);
code.addGetstatic(NULL_INTERCEPTOR_HOLDER, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
int pc = code.currentPc();
code.addAload(0);
int s = addLoadParameters(code, cons.getParameterTypes(), 1);
code.addInvokespecial(superClass.getName(), "<init>", desc);
code.addOpcode(Opcode.RETURN);
code.setMaxLocals(s + 1);
CodeAttribute ca = code.toCodeAttribute();
minfo.setCodeAttribute(ca);
StackMapTable.Writer writer = new StackMapTable.Writer(32);
writer.sameFrame(pc);
ca.setAttribute(writer.toStackMapTable(cp));
return minfo;
}
示例5: doit
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError
{
if (gen.getMethodArgsLength(args) != 1)
throw new CompileError(Javac.proceedName
+ "() cannot take more than one parameter "
+ "for cast");
gen.atMethodArgs(args, new int[1], new int[1], new String[1]);
bytecode.addOpcode(Opcode.CHECKCAST);
bytecode.addIndex(index);
gen.setType(retType);
}
示例6: doit
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError
{
if (gen.getMethodArgsLength(args) != 1)
throw new CompileError(Javac.proceedName
+ "() cannot take more than one parameter "
+ "for instanceof");
gen.atMethodArgs(args, new int[1], new int[1], new String[1]);
bytecode.addOpcode(Opcode.INSTANCEOF);
bytecode.addIndex(index);
gen.setType(CtClass.booleanType);
}
示例7: doit
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
throws CompileError
{
bytecode.addOpcode(NEW);
bytecode.addIndex(newIndex);
bytecode.addOpcode(DUP);
gen.atMethodCallCore(newType, MethodInfo.nameInit, args,
false, true, -1, null);
gen.setType(newType);
}
示例8: doit
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected boolean doit(Bytecode b, int opcode) {
switch (opcode) {
case Opcode.RETURN :
break;
case ARETURN :
b.addAstore(var);
break;
case IRETURN :
b.addIstore(var);
break;
case LRETURN :
b.addLstore(var);
break;
case DRETURN :
b.addDstore(var);
break;
case FRETURN :
b.addFstore(var);
break;
default :
throw new RuntimeException("fatal");
}
b.addOpcode(Opcode.GOTO);
b.addIndex(target - b.currentPc() + 3);
return true;
}
示例9: atSyncStmnt
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private void atSyncStmnt(Stmnt st) throws CompileError {
int nbreaks = getListSize(breakList);
int ncontinues = getListSize(continueList);
compileExpr(st.head());
if (exprType != CLASS && arrayDim == 0)
throw new CompileError("bad type expr for synchronized block");
Bytecode bc = bytecode;
final int var = bc.getMaxLocals();
bc.incMaxLocals(1);
bc.addOpcode(DUP);
bc.addAstore(var);
bc.addOpcode(MONITORENTER);
ReturnHook rh = new ReturnHook(this) {
protected boolean doit(Bytecode b, int opcode) {
b.addAload(var);
b.addOpcode(MONITOREXIT);
return false;
}
};
int pc = bc.currentPc();
Stmnt body = (Stmnt)st.tail();
if (body != null)
body.accept(this);
int pc2 = bc.currentPc();
int pc3 = 0;
if (!hasReturned) {
rh.doit(bc, 0); // the 2nd arg is ignored.
bc.addOpcode(Opcode.GOTO);
pc3 = bc.currentPc();
bc.addIndex(0);
}
if (pc < pc2) { // if the body is not empty
int pc4 = bc.currentPc();
rh.doit(bc, 0); // the 2nd arg is ignored.
bc.addOpcode(ATHROW);
bc.addExceptionHandler(pc, pc2, pc4, 0);
}
if (!hasReturned)
bc.write16bit(pc3, bc.currentPc() - pc3 + 1);
rh.remove(this);
if (getListSize(breakList) != nbreaks
|| getListSize(continueList) != ncontinues)
throw new CompileError(
"sorry, cannot break/continue in synchronized block");
}
示例10: jsrJmp
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private void jsrJmp(Bytecode b) {
b.addOpcode(Opcode.GOTO);
jsrList.add(new int[] {b.currentPc(), var});
b.addIndex(0);
}
示例11: atTryStmnt
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected void atTryStmnt(Stmnt st) throws CompileError {
Bytecode bc = bytecode;
Stmnt body = (Stmnt)st.getLeft();
if (body == null)
return;
ASTList catchList = (ASTList)st.getRight().getLeft();
Stmnt finallyBlock = (Stmnt)st.getRight().getRight().getLeft();
ArrayList gotoList = new ArrayList();
JsrHook jsrHook = null;
if (finallyBlock != null)
jsrHook = new JsrHook(this);
int start = bc.currentPc();
body.accept(this);
int end = bc.currentPc();
if (start == end)
throw new CompileError("empty try block");
boolean tryNotReturn = !hasReturned;
if (tryNotReturn) {
bc.addOpcode(Opcode.GOTO);
gotoList.add(new Integer(bc.currentPc()));
bc.addIndex(0); // correct later
}
int var = getMaxLocals();
incMaxLocals(1);
while (catchList != null) {
// catch clause
Pair p = (Pair)catchList.head();
catchList = catchList.tail();
Declarator decl = (Declarator)p.getLeft();
Stmnt block = (Stmnt)p.getRight();
decl.setLocalVar(var);
CtClass type = resolver.lookupClassByJvmName(decl.getClassName());
decl.setClassName(MemberResolver.javaToJvmName(type.getName()));
bc.addExceptionHandler(start, end, bc.currentPc(), type);
bc.growStack(1);
bc.addAstore(var);
hasReturned = false;
if (block != null)
block.accept(this);
if (!hasReturned) {
bc.addOpcode(Opcode.GOTO);
gotoList.add(new Integer(bc.currentPc()));
bc.addIndex(0); // correct later
tryNotReturn = true;
}
}
if (finallyBlock != null) {
jsrHook.remove(this);
// catch (any) clause
int pcAnyCatch = bc.currentPc();
bc.addExceptionHandler(start, pcAnyCatch, pcAnyCatch, 0);
bc.growStack(1);
bc.addAstore(var);
hasReturned = false;
finallyBlock.accept(this);
if (!hasReturned) {
bc.addAload(var);
bc.addOpcode(ATHROW);
}
addFinally(jsrHook.jsrList, finallyBlock);
}
int pcEnd = bc.currentPc();
patchGoto(gotoList, pcEnd);
hasReturned = !tryNotReturn;
if (finallyBlock != null) {
if (tryNotReturn)
finallyBlock.accept(this);
}
}