本文整理汇总了Java中scouter.javassist.bytecode.StackMapTable类的典型用法代码示例。如果您正苦于以下问题:Java StackMapTable类的具体用法?Java StackMapTable怎么用?Java StackMapTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StackMapTable类属于scouter.javassist.bytecode包,在下文中一共展示了StackMapTable类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: make
import scouter.javassist.bytecode.StackMapTable; //导入依赖的package包/类
/**
* Computes the stack map table of the given method and returns it.
* It returns null if the given method does not have to have a
* stack map table or it includes JSR.
*/
public static StackMapTable make(ClassPool classes, MethodInfo minfo)
throws BadBytecode
{
CodeAttribute ca = minfo.getCodeAttribute();
if (ca == null)
return null;
TypedBlock[] blocks;
try {
blocks = TypedBlock.makeBlocks(minfo, ca, true);
}
catch (BasicBlock.JsrBytecode e) {
return null;
}
if (blocks == null)
return null;
MapMaker mm = new MapMaker(classes, minfo, ca);
try {
mm.make(blocks, ca.getCode());
}
catch (BadBytecode bb) {
throw new BadBytecode(minfo, bb);
}
return mm.toStackMap(blocks);
}
示例2: toStackMap
import scouter.javassist.bytecode.StackMapTable; //导入依赖的package包/类
public StackMapTable toStackMap(TypedBlock[] blocks) {
StackMapTable.Writer writer = new StackMapTable.Writer(32);
int n = blocks.length;
TypedBlock prev = blocks[0];
int offsetDelta = prev.length;
if (prev.incoming > 0) { // the first instruction is a branch target.
writer.sameFrame(0);
offsetDelta--;
}
for (int i = 1; i < n; i++) {
TypedBlock bb = blocks[i];
if (isTarget(bb, blocks[i - 1])) {
bb.resetNumLocals();
int diffL = stackMapDiff(prev.numLocals, prev.localsTypes,
bb.numLocals, bb.localsTypes);
toStackMapBody(writer, bb, diffL, offsetDelta, prev);
offsetDelta = bb.length - 1;
prev = bb;
}
else if (bb.incoming == 0) {
// dead code.
writer.sameFrame(offsetDelta);
offsetDelta = bb.length - 1;
prev = bb;
}
else
offsetDelta += bb.length;
}
return writer.toStackMapTable(cpool);
}
示例3: addParameter2
import scouter.javassist.bytecode.StackMapTable; //导入依赖的package包/类
private void addParameter2(int where, CtClass type, String desc)
throws BadBytecode
{
CodeAttribute ca = methodInfo.getCodeAttribute();
if (ca != null) {
int size = 1;
char typeDesc = 'L';
int classInfo = 0;
if (type.isPrimitive()) {
CtPrimitiveType cpt = (CtPrimitiveType)type;
size = cpt.getDataSize();
typeDesc = cpt.getDescriptor();
}
else
classInfo = methodInfo.getConstPool().addClassInfo(type);
ca.insertLocalVar(where, size);
LocalVariableAttribute va
= (LocalVariableAttribute)ca.getAttribute(LocalVariableAttribute.tag);
if (va != null)
va.shiftIndex(where, size);
LocalVariableTypeAttribute lvta
= (LocalVariableTypeAttribute)ca.getAttribute(LocalVariableTypeAttribute.tag);
if (lvta != null)
lvta.shiftIndex(where, size);
StackMapTable smt = (StackMapTable)ca.getAttribute(StackMapTable.tag);
if (smt != null)
smt.insertLocal(where, StackMapTable.typeTagOf(typeDesc), classInfo);
StackMap sm = (StackMap)ca.getAttribute(StackMap.tag);
if (sm != null)
sm.insertLocal(where, StackMapTable.typeTagOf(typeDesc), classInfo);
}
}
示例4: makeConstructor
import scouter.javassist.bytecode.StackMapTable; //导入依赖的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: is2WordType
import scouter.javassist.bytecode.StackMapTable; //导入依赖的package包/类
public boolean is2WordType() {
return typeTag == StackMapTable.LONG
|| typeTag == StackMapTable.DOUBLE;
}
示例6: getTypeTag
import scouter.javassist.bytecode.StackMapTable; //导入依赖的package包/类
public int getTypeTag() {
return StackMapTable.NULL;
}
示例7: transform
import scouter.javassist.bytecode.StackMapTable; //导入依赖的package包/类
/**
* Replace a sequence of
* NEW classname
* DUP
* ...
* INVOKESPECIAL
* with
* NOP
* NOP
* ...
* INVOKESTATIC trapMethod in trapClass
*/
public int transform(CtClass clazz, int pos, CodeIterator iterator,
ConstPool cp) throws CannotCompileException
{
int index;
int c = iterator.byteAt(pos);
if (c == NEW) {
index = iterator.u16bitAt(pos + 1);
if (cp.getClassInfo(index).equals(classname)) {
if (iterator.byteAt(pos + 3) != DUP)
throw new CannotCompileException(
"NEW followed by no DUP was found");
iterator.writeByte(NOP, pos);
iterator.writeByte(NOP, pos + 1);
iterator.writeByte(NOP, pos + 2);
iterator.writeByte(NOP, pos + 3);
++nested;
StackMapTable smt
= (StackMapTable)iterator.get().getAttribute(StackMapTable.tag);
if (smt != null)
smt.removeNew(pos);
StackMap sm
= (StackMap)iterator.get().getAttribute(StackMap.tag);
if (sm != null)
sm.removeNew(pos);
}
}
else if (c == INVOKESPECIAL) {
index = iterator.u16bitAt(pos + 1);
int typedesc = cp.isConstructor(classname, index);
if (typedesc != 0 && nested > 0) {
int methodref = computeMethodref(typedesc, cp);
iterator.writeByte(INVOKESTATIC, pos);
iterator.write16bit(methodref, pos + 1);
--nested;
}
}
return pos;
}