如何在C++中的big-endian和little-endian值之间进行转换?我正在使用VC++ 6.0.当我使用_byteswap_ulong()函数时,它需要头文件intrin.h.当我包含标题时,它报告错误说不兼容的编译器,而intrin.h用于gcc编译器.那么除了这个函数之外,还有其他函数可以在VC++中的big-endian和little-endian值之间进行转换吗?
我听说很多框架(Struts,Spring,Hibernate,AspectJ)在内部使用字节码操作.使用字节码操作有哪些令人信服的理由?我期待每个特定框架至少有一个用例的答案.
我正在使用Javassist ProxyFactory创建一个Proxy类,其代码如下:
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(entity.getClass());
factory.setInterfaces(new Class[] { MyCustomInterface.class });
.....
Class clazz = factory.createClass();
Object result = clazz.newInstance();
Run Code Online (Sandbox Code Playgroud)
问题是我还需要在类中添加一个字段.但是,如果我这样做,CtClass proxy = ClassPool.getDefault().get(clazz.getName());他会嗤之以鼻NotFoundException
如何添加使用createClass创建的类的字段?有没有更好的方法来做我想做的事情?
所以基本上我试图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
我正在尝试删除test()以下程序中的方法主体,以便不向控制台打印任何内容.我正在使用ASM 5.2,但我尝试的一切似乎都没有任何影响.
有人可以解释我做错了什么,并指出了一些关于ASM的最新教程或文档吗?我在Stackoverflow和ASM网站上发现的几乎所有内容都显得过时和/或无用.
public class BytecodeMods {
public static void main(String[] args) throws Exception {
disableMethod(BytecodeMods.class.getMethod("test"));
test();
}
public static void test() {
System.out.println("This is a test");
}
private static void disableMethod(Method method) {
new MethodReplacer()
.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, method.getName(), Type.getMethodDescriptor(method), null, null);
}
public static class MethodReplacer extends ClassVisitor {
public MethodReplacer() {
super(Opcodes.ASM5);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return null;
}
}
}
Run Code Online (Sandbox Code Playgroud) 该ASM引导谈到构造函数:
Run Code Online (Sandbox Code Playgroud)package pkg; public class Bean { private int f; public int getF() { return this.f; } public void setF(int f) { this.f = f; } }Bean类还具有由编译器生成的默认公共构造函数,因为程序员没有定义任何显式构造函数。此默认的公共构造函数生成为
Bean() { super(); }。该构造函数的字节码如下:Run Code Online (Sandbox Code Playgroud)ALOAD 0 INVOKESPECIAL java/lang/Object <init> ()V RETURN第一条指令压
this入操作数堆栈。第二条指令从堆栈中弹出该值,并调用类中<init>定义的方法Object。这对应于super()调用,即对超类的构造函数的调用Object。您可以在此处看到,在编译类和源类中,构造函数的名称不同:在编译类中,它们总是命名为<init>,而在源类中,它们具有定义它们的类的名称。最后,最后一条指令返回给调用者。
this在构造函数的第一条指令之前,JVM已知的值如何?
现在,为了增长知识,我一直在研究简单的字节码检测机制,并希望在我公司未来的项目中使用它们。
我已经浏览了几篇在线文章。但是我对术语“构建时间”和“加载时间”感到困惑。
如果有人澄清这些术语的含义,我将非常感激
谢谢,
努万·阿兰巴奇
我想用新内容替换方法体(sample.class:sayHello方法),然后执行sample.class.原来的sayHelo声明是:
public int sayHello(String args){
}
Run Code Online (Sandbox Code Playgroud)
我想修改它的主体:
System.out.println("sxu says: hello world!");
return 1;
Run Code Online (Sandbox Code Playgroud)
但是样例执行结果抛出异常:
Exception in thread "main" java.lang.VerifyError: Operand stack overflow
Exception Details:
Location:
code/sxu/demo/data/sample.sayHello(Ljava/lang/String;)I @4: ldc
Reason:
Exceeded max stack size.
Current Frame:
bci: @4
flags: { }
locals: { 'code/sxu/demo/data/sample', 'java/lang/String' }
stack: { 'code/sxu/demo/data/sample', 'java/io/PrintStream' }
Bytecode:
0000000: 2ab2 0028 122a b600 1704 acb2 0028 2bb6
0000010: 0017 04ac
Run Code Online (Sandbox Code Playgroud)
我使用asm工具,我的代码中有三个java类:
public class Adapt extends ClassLoader {
@Override
protected synchronized Class<?> loadClass(final String name,
final boolean resolve) …Run Code Online (Sandbox Code Playgroud) 根据这个主题: 获取java.lang.VerifyError的原因
java.lang.VerifyError 获取执行jvm的版本是否比用于编译的jvm更新.
我们始终可以使用以下jvm选项解决此问题:-XX:-UseSplitVerifier.
根据这个:
使用此选项是"非常安全".
因此,我不明白为什么java.lang.VerifyError是阻止成功编译的问题.请澄清.也许对于检测字节码的库来说,它是不安全的?
我使用ASM库生成字节码,并且方法的"最大堆栈大小"将自动计算.在运行期间,我发现此值(最大堆栈大小)不正确.
我的源代码是:
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
....
MethodType initType = MethodType.methodType(void.class, clsList);
mv = cw.visitMethod(ACC_PUBLIC, "<init>", initType.toMethodDescriptorString(), null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/invoke/BaseTemplate", "<init>", "()V", false);
for(int i=0; i< list.size(); i++){
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1+i);
mv.visitFieldInsn(PUTFIELD, className, list.get(i).name(), Utils.getFieldDesc(list.get(i).type()));
}
mv.visitInsn(RETURN);
//mv.visitMaxs(2, 4); //Verify succeeds if uncomment this line.
mv.visitEnd();
....
//Verify generated code before class loading..
PrintWriter pw = new PrintWriter(System.out);
CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), true, pw);
Class<?> expClass =defineClass(..);
Run Code Online (Sandbox Code Playgroud)
上面的代码将生成字节码:
Classfile /C:/temp/TGWD.class
Last modified Mar 11, 2015; size …Run Code Online (Sandbox Code Playgroud)