本文整理汇总了Java中scouter.javassist.bytecode.Opcode类的典型用法代码示例。如果您正苦于以下问题:Java Opcode类的具体用法?Java Opcode怎么用?Java Opcode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Opcode类属于scouter.javassist.bytecode包,在下文中一共展示了Opcode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: atMethodBody
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
/**
* @param isCons true if super() must be called.
* false if the method is a class initializer.
*/
public void atMethodBody(Stmnt s, boolean isCons, boolean isVoid)
throws CompileError
{
if (s == null)
return;
if (isCons && needsSuperCall(s))
insertDefaultSuperCall();
hasReturned = false;
s.accept(this);
if (!hasReturned)
if (isVoid) {
bytecode.addOpcode(Opcode.RETURN);
hasReturned = true;
}
else
throw new CompileError("no return statement");
}
示例2: atCondExpr
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
public void atCondExpr(CondExpr expr) throws CompileError {
if (booleanExpr(false, expr.condExpr()))
expr.elseExpr().accept(this);
else {
int pc = bytecode.currentPc();
bytecode.addIndex(0); // correct later
expr.thenExpr().accept(this);
int dim1 = arrayDim;
bytecode.addOpcode(Opcode.GOTO);
int pc2 = bytecode.currentPc();
bytecode.addIndex(0);
bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
expr.elseExpr().accept(this);
if (dim1 != arrayDim)
throw new CompileError("type mismatch in ?:");
bytecode.write16bit(pc2, bytecode.currentPc() - pc2 + 1);
}
}
示例3: isEmpty
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
/**
* 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;
}
示例4: insertAfterAdvice
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private int insertAfterAdvice(Bytecode code, Javac jv, String src,
ConstPool cp, CtClass rtype, int varNo)
throws CompileError
{
int pc = code.currentPc();
if (rtype == CtClass.voidType) {
code.addOpcode(Opcode.ACONST_NULL);
code.addAstore(varNo);
jv.compileStmnt(src);
code.addOpcode(Opcode.RETURN);
if (code.getMaxLocals() < 1)
code.setMaxLocals(1);
}
else {
code.addStore(varNo, rtype);
jv.compileStmnt(src);
code.addLoad(varNo, rtype);
if (rtype.isPrimitive())
code.addOpcode(((CtPrimitiveType)rtype).getReturnOp());
else
code.addOpcode(Opcode.ARETURN);
}
return code.currentPc() - pc;
}
示例5: callFind2Methods
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
/**
* @param thisMethod might be null.
*/
private static void callFind2Methods(Bytecode code, String superMethod, String thisMethod,
int index, String desc, int classVar, int arrayVar) {
String findClass = RuntimeSupport.class.getName();
String findDesc
= "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/reflect/Method;)V";
code.addAload(classVar);
code.addLdc(superMethod);
if (thisMethod == null)
code.addOpcode(Opcode.ACONST_NULL);
else
code.addLdc(thisMethod);
code.addIconst(index);
code.addLdc(desc);
code.addAload(arrayVar);
code.addInvokestatic(findClass, "find2Methods", findDesc);
}
示例6: addReturn
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private static int addReturn(Bytecode code, Class type) {
if (type.isPrimitive()) {
if (type == Long.TYPE) {
code.addOpcode(Opcode.LRETURN);
return 2;
}
else if (type == Float.TYPE)
code.addOpcode(Opcode.FRETURN);
else if (type == Double.TYPE) {
code.addOpcode(Opcode.DRETURN);
return 2;
}
else if (type == Void.TYPE) {
code.addOpcode(Opcode.RETURN);
return 0;
}
else
code.addOpcode(Opcode.IRETURN);
}
else
code.addOpcode(Opcode.ARETURN);
return 1;
}
示例7: makeParameterList
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private static void makeParameterList(Bytecode code, Class[] params) {
int regno = 1;
int n = params.length;
code.addIconst(n);
code.addAnewarray("java/lang/Object");
for (int i = 0; i < n; i++) {
code.addOpcode(Opcode.DUP);
code.addIconst(i);
Class type = params[i];
if (type.isPrimitive())
regno = makeWrapper(code, type, regno);
else {
code.addAload(regno);
regno++;
}
code.addOpcode(Opcode.AASTORE);
}
}
示例8: addUnwrapper
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private static void addUnwrapper(Bytecode code, Class type) {
if (type.isPrimitive()) {
if (type == Void.TYPE)
code.addOpcode(Opcode.POP);
else {
int index = FactoryHelper.typeIndex(type);
String wrapper = FactoryHelper.wrapperTypes[index];
code.addCheckcast(wrapper);
code.addInvokevirtual(wrapper,
FactoryHelper.unwarpMethods[index],
FactoryHelper.unwrapDesc[index]);
}
}
else
code.addCheckcast(type.getName());
}
示例9: makeWriteReplace
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private static MethodInfo makeWriteReplace(ConstPool cp) {
MethodInfo minfo = new MethodInfo(cp, "writeReplace", "()Ljava/lang/Object;");
String[] list = new String[1];
list[0] = "java.io.ObjectStreamException";
ExceptionsAttribute ea = new ExceptionsAttribute(cp);
ea.setExceptions(list);
minfo.setExceptionsAttribute(ea);
Bytecode code = new Bytecode(cp, 0, 1);
code.addAload(0);
code.addInvokestatic("RuntimeSupport",
"makeSerializedProxy",
"(Ljava/lang/Object;)Ljavassist/util/proxy/SerializedProxy;");
code.addOpcode(Opcode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
return minfo;
}
示例10: getComponentType
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
/**
* Returns the type of array components. If the created array is
* a two-dimensional array of <tt>int</tt>,
* the type returned by this method is
* not <tt>int[]</tt> but <tt>int</tt>.
*/
public CtClass getComponentType() throws NotFoundException {
if (opcode == Opcode.NEWARRAY) {
int atype = iterator.byteAt(currentPos + 1);
return getPrimitiveType(atype);
}
else if (opcode == Opcode.ANEWARRAY
|| opcode == Opcode.MULTIANEWARRAY) {
int index = iterator.u16bitAt(currentPos + 1);
String desc = getConstPool().getClassInfo(index);
int dim = Descriptor.arrayDimension(desc);
desc = Descriptor.toArrayComponent(desc, dim);
return Descriptor.toCtClass(desc, thisClass.getClassPool());
}
else
throw new RuntimeException("bad opcode: " + opcode);
}
示例11: getPrimitiveType
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
CtClass getPrimitiveType(int atype) {
switch (atype) {
case Opcode.T_BOOLEAN :
return CtClass.booleanType;
case Opcode.T_CHAR :
return CtClass.charType;
case Opcode.T_FLOAT :
return CtClass.floatType;
case Opcode.T_DOUBLE :
return CtClass.doubleType;
case Opcode.T_BYTE :
return CtClass.byteType;
case Opcode.T_SHORT :
return CtClass.shortType;
case Opcode.T_INT :
return CtClass.intType;
case Opcode.T_LONG :
return CtClass.longType;
default :
throw new RuntimeException("bad atype: " + atype);
}
}
示例12: doit
import scouter.javassist.bytecode.Opcode; //导入依赖的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);
}
示例13: addFinally
import scouter.javassist.bytecode.Opcode; //导入依赖的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());
}
}
}
示例14: atIfStmnt
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private void atIfStmnt(Stmnt st) throws CompileError {
ASTree expr = st.head();
Stmnt thenp = (Stmnt)st.tail().head();
Stmnt elsep = (Stmnt)st.tail().tail().head();
if (compileBooleanExpr(false, expr)) {
hasReturned = false;
if (elsep != null)
elsep.accept(this);
return;
}
int pc = bytecode.currentPc();
int pc2 = 0;
bytecode.addIndex(0); // correct later
hasReturned = false;
if (thenp != null)
thenp.accept(this);
boolean thenHasReturned = hasReturned;
hasReturned = false;
if (elsep != null && !thenHasReturned) {
bytecode.addOpcode(Opcode.GOTO);
pc2 = bytecode.currentPc();
bytecode.addIndex(0);
}
bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
if (elsep != null) {
elsep.accept(this);
if (!thenHasReturned)
bytecode.write16bit(pc2, bytecode.currentPc() - pc2 + 1);
hasReturned = thenHasReturned && hasReturned;
}
}
示例15: atWhileStmnt
import scouter.javassist.bytecode.Opcode; //导入依赖的package包/类
private void atWhileStmnt(Stmnt st, boolean notDo) throws CompileError {
ArrayList prevBreakList = breakList;
ArrayList prevContList = continueList;
breakList = new ArrayList();
continueList = new ArrayList();
ASTree expr = st.head();
Stmnt body = (Stmnt)st.tail();
int pc = 0;
if (notDo) {
bytecode.addOpcode(Opcode.GOTO);
pc = bytecode.currentPc();
bytecode.addIndex(0);
}
int pc2 = bytecode.currentPc();
if (body != null)
body.accept(this);
int pc3 = bytecode.currentPc();
if (notDo)
bytecode.write16bit(pc, pc3 - pc + 1);
boolean alwaysBranch = compileBooleanExpr(true, expr);
if (alwaysBranch) {
bytecode.addOpcode(Opcode.GOTO);
alwaysBranch = breakList.size() == 0;
}
bytecode.addIndex(pc2 - bytecode.currentPc() + 1);
patchGoto(breakList, bytecode.currentPc());
patchGoto(continueList, pc3);
continueList = prevContList;
breakList = prevBreakList;
hasReturned = alwaysBranch;
}