本文整理匯總了Java中org.objectweb.asm.util.Textifier類的典型用法代碼示例。如果您正苦於以下問題:Java Textifier類的具體用法?Java Textifier怎麽用?Java Textifier使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Textifier類屬於org.objectweb.asm.util包,在下文中一共展示了Textifier類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
final String k2 = "org/apache/drill/Pickle.class";
final URL url = Resources.getResource(k2);
final byte[] clazz = Resources.toByteArray(url);
final ClassReader cr = new ClassReader(clazz);
final ClassWriter cw = writer();
final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
cr.accept(v2, ClassReader.EXPAND_FRAMES );//| ClassReader.SKIP_DEBUG);
final byte[] output = cw.toByteArray();
Files.write(output, new File("/src/scratch/bytes/S.class"));
check(output);
final DrillConfig c = DrillConfig.forClient();
final SystemOptionManager m = new SystemOptionManager(c, new LocalPStoreProvider(c));
m.init();
try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
clz.getMethod("x").invoke(null);
}
}
示例2: dump
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
private static void dump(MethodNode method) {
Textifier textifier = new Textifier();
method.accept(new TraceMethodVisitor(textifier));
StringWriter writer = new StringWriter();
try (PrintWriter pw = new PrintWriter(writer)) {
textifier.print(pw);
}
System.out.println(writer.toString());
}
示例3: toString
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
/** compiles to bytecode, and returns debugging output */
static String toString(Class<?> iface, String source, CompilerSettings settings) {
StringWriter output = new StringWriter();
PrintWriter outputWriter = new PrintWriter(output);
Textifier textifier = new Textifier();
try {
Compiler.compile(iface, "<debugging>", source, settings, textifier);
} catch (Exception e) {
textifier.print(outputWriter);
e.addSuppressed(new Exception("current bytecode: \n" + output));
IOUtils.reThrowUnchecked(e);
throw new AssertionError();
}
textifier.print(outputWriter);
return output.toString();
}
示例4: visitEnd
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
@Override
public void visitEnd() {
try {
accept(inner);
super.visitEnd();
} catch(Exception e){
Textifier t = new Textifier();
accept(new TraceMethodVisitor(t));
StringBuilderWriter sw = new StringBuilderWriter();
PrintWriter pw = new PrintWriter(sw);
t.print(pw);
pw.flush();
String bytecode = sw.getBuilder().toString();
logger.error(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e);
throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e);
}
}
示例5: viewByteCode
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
/**
* 格式化輸出字節碼
* @param bytecode
*/
public static void viewByteCode(byte[] bytecode) {
ClassReader cr = new ClassReader(bytecode);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
final List<MethodNode> mns = cn.methods;
Printer printer = new Textifier();
TraceMethodVisitor mp = new TraceMethodVisitor(printer);
for (MethodNode mn : mns) {
InsnList inList = mn.instructions;
System.out.println(mn.name);
for (int i = 0; i < inList.size(); i++) {
inList.get(i).accept(mp);
StringWriter sw = new StringWriter();
printer.print(new PrintWriter(sw));
printer.getText().clear();
System.out.print(sw.toString());
}
}
}
示例6: main
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
final String k2 = "org/apache/drill/Pickle.class";
final URL url = Resources.getResource(k2);
final byte[] clazz = Resources.toByteArray(url);
final ClassReader cr = new ClassReader(clazz);
final ClassWriter cw = writer();
final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
cr.accept(v2, ClassReader.EXPAND_FRAMES );//| ClassReader.SKIP_DEBUG);
final byte[] output = cw.toByteArray();
Files.write(output, new File("/src/scratch/bytes/S.class"));
check(output);
final DrillConfig c = DrillConfig.forClient();
final SystemOptionManager m = new SystemOptionManager(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(c), new LocalPersistentStoreProvider(c), c);
m.init();
try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
clz.getMethod("x").invoke(null);
}
}
示例7: visitEnd
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
@Override
public void visitEnd() {
super.visitEnd();
if (!found && errorNoMatch) {
StringWriter output = new StringWriter();
PrintWriter writer = new PrintWriter(output);
writer.append("Cannot find nodes");
if (methods.size() > 0) {
writer.append(" for methods ").append(methods.toString());
}
writer.println();
Printer printer = new Textifier();
TraceMethodVisitor visitor = new TraceMethodVisitor(printer);
for (AbstractInsnNode node : nodes) {
node.accept(visitor);
}
printer.print(writer);
throw new IllegalStateException(output.toString());
}
}
示例8: viewByteCode
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
public static void viewByteCode(byte[] bytecode) {
ClassReader cr = new ClassReader(bytecode);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
final List<MethodNode> mns = cn.methods;
Printer printer = new Textifier();
TraceMethodVisitor mp = new TraceMethodVisitor(printer);
for (MethodNode mn : mns) {
InsnList inList = mn.instructions;
System.out.println(mn.name);
for (int i = 0; i < inList.size(); i++) {
inList.get(i).accept(mp);
StringWriter sw = new StringWriter();
printer.print(new PrintWriter(sw));
printer.getText().clear();
System.out.print(sw.toString());
}
}
}
示例9: trace
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
/** Returns a human readable string for the code that this {@link BytecodeProducer} generates. */
public final String trace() {
// TODO(lukes): textifier has support for custom label names by overriding appendLabel.
// Consider trying to make use of (using the Label.info field? adding a custom NamedLabel
// sub type?)
Textifier textifier =
new Textifier(Opcodes.ASM6) {
{
// reset tab sizes. Since we don't care about formatting class names or method
// signatures (only code). We only need to set the tab2,tab3 and ltab settings (tab is
// for class members).
this.tab = null; // trigger an error if used.
this.tab2 = " "; // tab setting for instructions
this.tab3 = ""; // tab setting for switch cases
this.ltab = ""; // tab setting for labels
}
};
gen(new CodeBuilder(new TraceMethodVisitor(textifier), 0, "trace", "()V"));
StringWriter writer = new StringWriter();
textifier.print(new PrintWriter(writer));
return writer.toString(); // Note textifier always adds a trailing newline
}
示例10: setUp
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
super.setUp();
jsr = new JSRInlinerAdapter(Opcodes.ASM5, null, 0, "m", "()V", null,
null) {
@Override
public void visitEnd() {
System.err.println("started w/ method:" + name);
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
for (int i = 0; i < instructions.size(); ++i) {
instructions.get(i).accept(mv);
System.err.print(Integer.toString(i + 100000).substring(1));
System.err.print(" : " + t.text.get(i));
}
super.visitEnd();
System.err.println("finished w/ method:" + name);
}
};
exp = new MethodNode(0, "m", "()V", null, null);
}
示例11: printMethod
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
public static void printMethod(PrintStream out, MethodNode method) {
final Textifier textifier = new Textifier();
final TraceMethodVisitor mv = new TraceMethodVisitor(textifier);
out.println(method.name + method.desc);
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
final StringBuffer s = new StringBuffer();
while (s.length() < method.maxStack + method.maxLocals + 1) {
s.append(' ');
}
out.print(Integer.toString(j + 100000).substring(1));
out.print(" " + s + " : " + textifier.text.get(j));
}
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
out.print(" " + textifier.text.get(method.instructions.size()+j));
}
out.println(" MAXSTACK " + method.maxStack);
out.println(" MAXLOCALS " + method.maxLocals);
out.println();
}
示例12: setUp
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
super.setUp();
jsr = new JSRInlinerAdapter(null, 0, "m", "()V", null, null) {
@Override
public void visitEnd() {
System.err.println("started w/ method:" + name);
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
for (int i = 0; i < instructions.size(); ++i) {
instructions.get(i).accept(mv);
System.err.print(Integer.toString(i + 100000).substring(1));
System.err.print(" : " + t.text.get(i));
}
super.visitEnd();
System.err.println("finished w/ method:" + name);
}
};
exp = new MethodNode(0, "m", "()V", null, null);
}
示例13: toString
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
@Override
public String toString() {
triggerDelayedParsingIfNeccessary();
TraceMethodVisitor visitor = new TraceMethodVisitor(new Textifier());
node.accept(visitor);
StringWriter writer = new StringWriter();
visitor.p.print(new PrintWriter(writer));
return writer.toString();
}
示例14: writeBytecodeToDisk
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
private void writeBytecodeToDisk(final byte[] clazz, Path folder) throws IOException {
final ClassReader reader = new ClassReader(clazz);
CharArrayWriter buffer = new CharArrayWriter();
reader.accept(new TraceClassVisitor(null, new Textifier(), new PrintWriter(
buffer)), ClassReader.EXPAND_FRAMES);
Path outFile = folder.resolve(currentClass.asJavaName() + ".txt");
Files.write(outFile, Collections.singleton(buffer.toString()), StandardCharsets.UTF_8, StandardOpenOption.CREATE);
}
示例15: traceMethod
import org.objectweb.asm.util.Textifier; //導入依賴的package包/類
public void traceMethod(String className, final String method) {
new ClassReader(inMemoryClassFileManager.classBytes(className)).accept(
new ClassVisitor(Opcodes.ASM5) {
PrintWriter pw = new PrintWriter(System.out);
Textifier p = new Textifier();
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if(name.equals(method)) {
p.visitMethod(access, name, desc, signature, exceptions);
return new TraceMethodVisitor(p);
}
return null;
}
@Override
public void visitEnd() {
p.visitClassEnd();
if (pw != null) {
p.print(pw);
pw.flush();
}
}
},
ClassReader.SKIP_FRAMES
);
}