我猜测以下两个函数编译为完全相同的字节码,但我想问一下这个问题.是否在不需要降低性能的情况下限定方法调用?
例如:
package com.my;
import android.app.Activity;
import android.os.Bundle;
public class Main extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.main); // Fully qualified
setContentView(R.layout.main); // Not fully qualified
}
}
Run Code Online (Sandbox Code Playgroud)
标准是使用后者,但完全合格的呼叫this.setContentView()是否有任何负面影响?
我试图在java类文件中找到类初始化程序.我可以找到方法没问题,但是如果在类文件中找不到main,那么我希望它找到类初始化程序并在那里注入代码.
如何使用Javassist找到类的初始化程序?
我修改了程序集的字节码以摆脱错误,现在当我尝试使用它时,我得到一个InvalidProgramException.我所做的就是用NOPS代替这个代码:
catch (Exception exception1)
{
Exception exception = exception1;
if (exception as InvalidValueException == null)
{
throw new InvalidGenerationException(2);
}
else
{
throw exception;
}
}
Run Code Online (Sandbox Code Playgroud)
IL之前:
catch [mscorlib]System.Exception
{
IL_022f: stloc.s exception
IL_0231: ldloc.s exception
IL_0233: isinst Custom.InvalidValueException
IL_0238: brfalse.s IL_023d
IL_023a: ldloc.s exception
IL_023c: throw
IL_023d: ldc.i4.1
IL_023e: newobj instance void Custom.InvalidGenerationException ...
IL_0243: throw
}
Run Code Online (Sandbox Code Playgroud)
IL之后:
catch [mscorlib]System.Exception
{
IL_022f: nop
IL_0230: nop
IL_0231: nop
IL_0232: nop
IL_0233: nop
IL_0234: nop
IL_0235: nop
IL_0236: nop
IL_0237: nop …Run Code Online (Sandbox Code Playgroud) 我运行薄荷13并使用apt-get包管理系统安装了python 3.2 .我也安装了python 2.7和3.2 pycompile似乎是一个包装python 2.7代码和抛出python 3.2代码的异常.
我环顾四周,试图安装一些软件包,但无法找到python 3.2的pycompile.如何为python 3.2获得pycompile工作?
类定义存储在方法区域中,如Java虚拟机规范所述(Java®虚拟机规范Java SE 7版):
方法区域是在虚拟机启动时创建的.虽然方法区域在逻辑上是堆的一部分,但是简单的实现可能选择不垃圾收集或压缩它.
我们知道,像ASM,cglib,javassist,Hibernate和Spring框架这样的字节码工具正在使用它们.对于公共类文件,JVM加载并解析和初始化并最终使用它,我对JVM如何动态处理字节码工具生成的类感到困惑.我的问题是:
如果JVM加载,则将动态类解析并初始化为公共类文件?
它们也存储在方法区域中吗?
JVM如何卸载和清理动态类定义以防止自身发生OutOfMemoryError?
以下例外:
Exception in thread "main" java.lang.NullPointerException
at javaapplication7.App.main(App.java:8)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)
从代码抛出:
Object o = n1.getObj().getObj().getObj().getObj();
Run Code Online (Sandbox Code Playgroud)
因此,从堆栈跟踪中不清楚哪个元素实际上是null.有没有一种方法可以在没有调试的情况下找到它?也许其他一些JVM会做什么?
所以基本上我试图System.out.println("hey");
在方法的最后添加一个简单的.我使用了树API.但是我一直收到这个错误:
java.lang.VerifyError:期望分支目标38处的stackmap帧
这是我的代码:
public class MethodNodeCustom extends MethodNode {
public MethodNodeCustom(int paramInt, String paramString1, String paramString2, String paramString3, String[] paramArrayOfString) {
this(327680, paramInt, paramString1, paramString2, paramString3, paramArrayOfString);
return;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public MethodNodeCustom(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3,
String[] paramArrayOfString) {
super(paramInt1);
this.access = paramInt2;
this.name = paramString1;
this.desc = paramString2;
this.signature = paramString3;
this.exceptions = new ArrayList((paramArrayOfString == null) ? 0 : paramArrayOfString.length);
int i = ((paramInt2 & 0x400) != 0) …Run Code Online (Sandbox Code Playgroud) java bytecode bytecode-manipulation java-bytecode-asm jvm-bytecode
// the java source code
public class Demo {
private final Object lock = new Object();
public void read() {
synchronized (lock) {
// more code here ...
}
}
}
// the decompiled .class file
public class Demo {
private final Object lock = new Object();
public void read() {
// Why Java compiler add this line? Is the 'read this.lock' redundant?
Object var1 = this.lock;
synchronized(this.lock) {
// more code here ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
字节码在这里:javap …
我有一些方法,其中包含像ILOAD这样的内容,我希望以某种方式在此指令之后获取堆栈的值.不只是打字,而是确切的价值.我知道我需要模拟方法执行才能做到这一点,但我不知道如何正确地做到这一点.
我有这样的测试方法叫main:
sipush 15649
istore_0 /* c */
getstatic java/lang/System.out:Ljava/io/PrintStream;
bipush 45
bipush 11
iload_0 /* c */
...
Run Code Online (Sandbox Code Playgroud)
我希望得到价值,加载iload_0.我试图制作分析器,然后看到帧值,但它们只包含值的类型,而不是我想要的.
ClassReader cr = new ClassReader(new FileInputStream(new File("input.class")));
ClassNode cn = new ClassNode(Opcodes.ASM5);
cr.accept(cn, 0);
Iterator<MethodNode> methods = cn.methods.iterator();
while (methods.hasNext()) {
MethodNode mn = methods.next();
if (!mn.name.equals("main")) continue;
AbstractInsnNode[] nodes = mn.instructions.toArray();
Analyzer analyzer = new Analyzer(new BasicInterpreter());
analyzer.analyze(cn.name, mn);
int i = -1;
for (Frame frame : analyzer.getFrames()) {
i++;
if (frame == null) continue; …Run Code Online (Sandbox Code Playgroud) 没有dup指令,可以让我复制堆栈顶部的指令。我可以使用哪个指令序列来复制此行为?
bytecode ×10
java ×7
jvm ×2
android ×1
il ×1
javassist ×1
jvm-bytecode ×1
methods ×1
performance ×1
pyc ×1
python ×1
python-3.x ×1
synchronized ×1
webassembly ×1