本文整理汇总了Java中scouter.javassist.bytecode.ConstPool类的典型用法代码示例。如果您正苦于以下问题:Java ConstPool类的具体用法?Java ConstPool怎么用?Java ConstPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstPool类属于scouter.javassist.bytecode包,在下文中一共展示了ConstPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultConstructor
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
/**
* Creates a default (public) constructor.
*
* <p>The created constructor takes no parameter. It calls
* <code>super()</code>.
*/
public static CtConstructor defaultConstructor(CtClass declaring)
throws CannotCompileException
{
CtConstructor cons = new CtConstructor((CtClass[])null, declaring);
ConstPool cp = declaring.getClassFile2().getConstPool();
Bytecode code = new Bytecode(cp, 1, 1);
code.addAload(0);
try {
code.addInvokespecial(declaring.getSuperclass(),
"<init>", "()V");
}
catch (NotFoundException e) {
throw new CannotCompileException(e);
}
code.add(Bytecode.RETURN);
// no need to construct a stack map table.
cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute());
return cons;
}
示例2: transform
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
/**
* Modify GETFIELD, GETSTATIC, PUTFIELD, and PUTSTATIC so that
* a different field is accessed. The new field must be declared
* in a superclass of the class in which the original field is
* declared.
*/
public int transform(CtClass clazz, int pos,
CodeIterator iterator, ConstPool cp)
{
int c = iterator.byteAt(pos);
if (c == GETFIELD || c == GETSTATIC
|| c == PUTFIELD || c == PUTSTATIC) {
int index = iterator.u16bitAt(pos + 1);
String typedesc
= TransformReadField.isField(clazz.getClassPool(), cp,
fieldClass, fieldname, isPrivate, index);
if (typedesc != null) {
if (newIndex == 0) {
int nt = cp.addNameAndTypeInfo(newFieldname,
typedesc);
newIndex = cp.addFieldrefInfo(
cp.addClassInfo(newClassname), nt);
constPool = cp;
}
iterator.write16bit(newIndex, pos + 1);
}
}
return pos;
}
示例3: transform
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
/**
* Modify INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC and INVOKEVIRTUAL
* so that a different method is invoked. The class name in the operand
* of these instructions might be a subclass of the target class specified
* by <code>classname</code>. This method transforms the instruction
* in that case unless the subclass overrides the target method.
*/
public int transform(CtClass clazz, int pos, CodeIterator iterator,
ConstPool cp) throws BadBytecode
{
int c = iterator.byteAt(pos);
if (c == INVOKEINTERFACE || c == INVOKESPECIAL
|| c == INVOKESTATIC || c == INVOKEVIRTUAL) {
int index = iterator.u16bitAt(pos + 1);
String cname = cp.eqMember(methodname, methodDescriptor, index);
if (cname != null && matchClass(cname, clazz.getClassPool())) {
int ntinfo = cp.getMemberNameAndType(index);
pos = match(c, pos, iterator,
cp.getNameAndTypeDescriptor(ntinfo), cp);
}
}
return pos;
}
示例4: match
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
protected int match(int c, int pos, CodeIterator iterator,
int typedesc, ConstPool cp) throws BadBytecode
{
if (newIndex == 0) {
int nt = cp.addNameAndTypeInfo(cp.addUtf8Info(newMethodname),
typedesc);
int ci = cp.addClassInfo(newClassname);
if (c == INVOKEINTERFACE)
newIndex = cp.addInterfaceMethodrefInfo(ci, nt);
else {
if (newMethodIsPrivate && c == INVOKEVIRTUAL)
iterator.writeByte(INVOKESPECIAL, pos);
newIndex = cp.addMethodrefInfo(ci, nt);
}
constPool = cp;
}
iterator.write16bit(newIndex, pos + 1);
return pos;
}
示例5: Annotation
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
/**
* Constructs an annotation that can be accessed through the interface
* represented by <code>clazz</code>. The values of the members are
* not specified.
*
* @param cp the constant pool table.
* @param clazz the interface.
* @throws NotFoundException when the clazz is not found
*/
public Annotation(ConstPool cp, CtClass clazz)
throws NotFoundException
{
// todo Enums are not supported right now.
this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
if (!clazz.isInterface())
throw new RuntimeException(
"Only interfaces are allowed for Annotation creation.");
CtMethod methods[] = clazz.getDeclaredMethods();
if (methods.length > 0) {
members = new LinkedHashMap();
}
for (int i = 0; i < methods.length; i++) {
CtClass returnType = methods[i].getReturnType();
addMemberValue(methods[i].getName(),
createMemberValue(cp, returnType));
}
}
示例6: insertAfterAdvice
import scouter.javassist.bytecode.ConstPool; //导入依赖的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;
}
示例7: override
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
private void override(String thisClassname, Method meth, String prefix,
int index, String desc, ClassFile cf, ConstPool cp, ArrayList forwarders)
throws CannotCompileException
{
Class declClass = meth.getDeclaringClass();
String delegatorName = prefix + index + meth.getName();
if (Modifier.isAbstract(meth.getModifiers()))
delegatorName = null;
else {
MethodInfo delegator
= makeDelegator(meth, desc, cp, declClass, delegatorName);
// delegator is not a bridge method. See Sec. 15.12.4.5 of JLS 3rd Ed.
delegator.setAccessFlags(delegator.getAccessFlags() & ~AccessFlag.BRIDGE);
cf.addMethod(delegator);
}
MethodInfo forwarder
= makeForwarder(thisClassname, meth, desc, cp, declClass,
delegatorName, index, forwarders);
cf.addMethod(forwarder);
}
示例8: getClassName
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
/**
* Returns the class name of the target object,
* which the method is called on.
*/
public String getClassName() {
String cname;
ConstPool cp = getConstPool();
int pos = currentPos;
int c = iterator.byteAt(pos);
int index = iterator.u16bitAt(pos + 1);
if (c == INVOKEINTERFACE)
cname = cp.getInterfaceMethodrefClassName(index);
else
cname = cp.getMethodrefClassName(index);
if (cname.charAt(0) == '[')
cname = Descriptor.toClassName(cname);
return cname;
}
示例9: makeConstructors
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
private void makeConstructors(String thisClassName, ClassFile cf,
ConstPool cp, String classname) throws CannotCompileException
{
Constructor[] cons = SecurityActions.getDeclaredConstructors(superClass);
// legacy: if we are not caching then we need to initialise the default handler
boolean doHandlerInit = !factoryUseCache;
for (int i = 0; i < cons.length; i++) {
Constructor c = cons[i];
int mod = c.getModifiers();
if (!Modifier.isFinal(mod) && !Modifier.isPrivate(mod)
&& isVisible(mod, basename, c)) {
MethodInfo m = makeConstructor(thisClassName, c, cp, superClass, doHandlerInit);
cf.addMethod(m);
}
}
}
示例10: makeDelegator
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
private MethodInfo makeDelegator(Method meth, String desc,
ConstPool cp, Class declClass, String delegatorName) {
MethodInfo delegator = new MethodInfo(cp, delegatorName, desc);
delegator.setAccessFlags(Modifier.FINAL | Modifier.PUBLIC
| (meth.getModifiers() & ~(Modifier.PRIVATE
| Modifier.PROTECTED
| Modifier.ABSTRACT
| Modifier.NATIVE
| Modifier.SYNCHRONIZED)));
setThrows(delegator, cp, meth);
Bytecode code = new Bytecode(cp, 0, 0);
code.addAload(0);
int s = addLoadParameters(code, meth.getParameterTypes(), 1);
Class targetClass = invokespecialTarget(declClass);
code.addInvokespecial(targetClass.isInterface(), cp.addClassInfo(targetClass.getName()),
meth.getName(), desc);
addReturn(code, meth.getReturnType());
code.setMaxLocals(++s);
delegator.setCodeAttribute(code.toCodeAttribute());
return delegator;
}
示例11: isEmpty
import scouter.javassist.bytecode.ConstPool; //导入依赖的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;
}
示例12: overrideMethods
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
private int overrideMethods(ClassFile cf, ConstPool cp, String className, ArrayList forwarders)
throws CannotCompileException
{
String prefix = makeUniqueName("_d", signatureMethods);
Iterator it = signatureMethods.iterator();
int index = 0;
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
String key = (String)e.getKey();
Method meth = (Method)e.getValue();
if (ClassFile.MAJOR_VERSION < ClassFile.JAVA_5 || !isBridge(meth))
if (testBit(signature, index)) {
override(className, meth, prefix, index,
keyToDesc(key, meth), cf, cp, forwarders);
}
index++;
}
return index;
}
示例13: buildExceptionInfo
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
ConstPool constPool = method.getConstPool();
ClassPool classes = clazz.getClassPool();
ExceptionTable table = method.getCodeAttribute().getExceptionTable();
ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
for (int i = 0; i < table.size(); i++) {
int index = table.catchType(i);
Type type;
try {
type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
} catch (NotFoundException e) {
throw new IllegalStateException(e.getMessage());
}
exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
}
return exceptions;
}
示例14: makeBlocks
import scouter.javassist.bytecode.ConstPool; //导入依赖的package包/类
/**
* Divides the method body into basic blocks.
* The type information of the first block is initialized.
*
* @param optimize if it is true and the method does not include
* branches, this method returns null.
*/
public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca,
boolean optimize)
throws BadBytecode
{
TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo);
if (optimize && blocks.length < 2)
if (blocks.length == 0 || blocks[0].incoming == 0)
return null;
ConstPool pool = minfo.getConstPool();
boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0;
blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(),
pool.getClassName(), minfo.getDescriptor(),
isStatic, minfo.isConstructor());
return blocks;
}
示例15: makeWriteReplace
import scouter.javassist.bytecode.ConstPool; //导入依赖的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;
}