本文整理汇总了Java中scouter.javassist.bytecode.Bytecode.addInvokestatic方法的典型用法代码示例。如果您正苦于以下问题:Java Bytecode.addInvokestatic方法的具体用法?Java Bytecode.addInvokestatic怎么用?Java Bytecode.addInvokestatic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scouter.javassist.bytecode.Bytecode
的用法示例。
在下文中一共展示了Bytecode.addInvokestatic方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
* Produces codes in which a new object is created and assigned to
* the field as the initial value.
*/
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
{
int stacksize;
code.addAload(0);
code.addAload(0);
if (stringParams == null)
stacksize = 2;
else
stacksize = compileStringParameter(code) + 2;
if (withConstructorParams)
stacksize += CtNewWrappedMethod.compileParameterList(code,
parameters, 1);
String typeDesc = Descriptor.of(type);
String mDesc = getDescriptor() + typeDesc;
code.addInvokestatic(objectType, methodName, mDesc);
code.addPutfield(Bytecode.THIS, name, typeDesc);
return stacksize;
}
示例2: compileIfStatic
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
* Produces codes for a static field.
*/
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
String desc;
int stacksize = 1;
if (stringParams == null)
desc = "()";
else {
desc = "([Ljava/lang/String;)";
stacksize += compileStringParameter(code);
}
String typeDesc = Descriptor.of(type);
code.addInvokestatic(objectType, methodName, desc + typeDesc);
code.addPutstatic(Bytecode.THIS, name, typeDesc);
return stacksize;
}
示例3: callFind2Methods
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的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);
}
示例4: makeWriteReplace
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的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;
}
示例5: delegator0
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static CtMethod delegator0(CtMethod delegate, CtClass declaring)
throws CannotCompileException, NotFoundException
{
MethodInfo deleInfo = delegate.getMethodInfo2();
String methodName = deleInfo.getName();
String desc = deleInfo.getDescriptor();
ConstPool cp = declaring.getClassFile2().getConstPool();
MethodInfo minfo = new MethodInfo(cp, methodName, desc);
minfo.setAccessFlags(deleInfo.getAccessFlags());
ExceptionsAttribute eattr = deleInfo.getExceptionsAttribute();
if (eattr != null)
minfo.setExceptionsAttribute(
(ExceptionsAttribute)eattr.copy(cp, null));
Bytecode code = new Bytecode(cp, 0, 0);
boolean isStatic = Modifier.isStatic(delegate.getModifiers());
CtClass deleClass = delegate.getDeclaringClass();
CtClass[] params = delegate.getParameterTypes();
int s;
if (isStatic) {
s = code.addLoadParameters(params, 0);
code.addInvokestatic(deleClass, methodName, desc);
}
else {
code.addLoad(0, deleClass);
s = code.addLoadParameters(params, 1);
code.addInvokespecial(deleClass, methodName, desc);
}
code.addReturn(delegate.getReturnType());
code.setMaxLocals(++s);
code.setMaxStack(s < 2 ? 2 : s); // for a 2-word return value
minfo.setCodeAttribute(code.toCodeAttribute());
// a stack map is not needed.
return new CtMethod(minfo, declaring);
}
示例6: makeBody0
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected static int makeBody0(CtClass clazz, ClassFile classfile,
CtMethod wrappedBody,
boolean isStatic, CtClass[] parameters,
CtClass returnType, ConstParameter cparam,
Bytecode code)
throws CannotCompileException
{
if (!(clazz instanceof CtClassType))
throw new CannotCompileException("bad declaring class"
+ clazz.getName());
if (!isStatic)
code.addAload(0);
int stacksize = compileParameterList(code, parameters,
(isStatic ? 0 : 1));
int stacksize2;
String desc;
if (cparam == null) {
stacksize2 = 0;
desc = ConstParameter.defaultDescriptor();
}
else {
stacksize2 = cparam.compile(code);
desc = cparam.descriptor();
}
checkSignature(wrappedBody, desc);
String bodyname;
try {
bodyname = addBodyMethod((CtClassType)clazz, classfile,
wrappedBody);
/* if an exception is thrown below, the method added above
* should be removed. (future work :<)
*/
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
if (isStatic)
code.addInvokestatic(Bytecode.THIS, bodyname, desc);
else
code.addInvokespecial(Bytecode.THIS, bodyname, desc);
compileReturn(code, returnType); // consumes 2 stack entries
if (stacksize < stacksize2 + 2)
stacksize = stacksize2 + 2;
return stacksize;
}
示例7: addClassInitializer
import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static void addClassInitializer(ClassFile cf, ConstPool cp,
String classname, int size, ArrayList forwarders)
throws CannotCompileException
{
FieldInfo finfo = new FieldInfo(cp, HOLDER, HOLDER_TYPE);
finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.STATIC);
cf.addField(finfo);
MethodInfo minfo = new MethodInfo(cp, "<clinit>", "()V");
minfo.setAccessFlags(AccessFlag.STATIC);
setThrows(minfo, cp, new Class[] { ClassNotFoundException.class });
Bytecode code = new Bytecode(cp, 0, 2);
code.addIconst(size * 2);
code.addAnewarray("java.lang.reflect.Method");
final int varArray = 0;
code.addAstore(varArray);
// forName() must be called here. Otherwise, the class might be
// invisible.
code.addLdc(classname);
code.addInvokestatic("java.lang.Class",
"forName", "(Ljava/lang/String;)Ljava/lang/Class;");
final int varClass = 1;
code.addAstore(varClass);
Iterator it = forwarders.iterator();
while (it.hasNext()) {
Find2MethodsArgs args = (Find2MethodsArgs)it.next();
callFind2Methods(code, args.methodName, args.delegatorName,
args.origIndex, args.descriptor, varClass, varArray);
}
code.addAload(varArray);
code.addPutstatic(classname, HOLDER, HOLDER_TYPE);
code.addLconst(SERIAL_VERSION_UID_VALUE);
code.addPutstatic(classname, SERIAL_VERSION_UID_FIELD, SERIAL_VERSION_UID_TYPE);
code.addOpcode(Bytecode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
}