bytecode

write java object into class file

♀尐吖头ヾ 提交于 2019-12-07 22:42:56
问题 Is there any way to write a loaded Java object into a .class file or is there any other type of file that can easily be read to represent an instance's properties. For example, CGLIB will create an proxy bean which extends another, i really want to export this enhanced bean out to a file to see how it was enhanced. 回答1: For cglib, instances can only be serialized and only if the instance's method interceptors support serialization. There is no other way. In order to get hold of a cglib

How to inspect the stack using an ASM visitor?

元气小坏坏 提交于 2019-12-07 21:22:01
问题 I am attempting to use the Java byte code engineering library ASM to perform static analysis. I have the situation where I would like to inspect the variables being assigned to a field. I have MethodVisitor which implements the visitFieldInsn() method. I am specifically looking for the putfield command. That is no problem. The problem is that when I encounter putfield , I want to be able to access the variable that's going to be assigned to the field. Specifically I want to access information

Code generation from three address code to JVM bytecode

a 夏天 提交于 2019-12-07 21:01:59
问题 I'm working on the byte code compiler for Renjin (R for the JVM) and am experimenting with translating our intermediate three address code (TAC) representation to byte code. All the textbooks on compilers that I've consulted discuss register allocation during code generation, but I haven't been able to find any resources for code generation on stack-based virtual machines like the JVM. Simple TAC instructions are trivial to translate into bytecode, but I get a bit lost when temporaries are

Can I redefine private methods using Byte Buddy?

北慕城南 提交于 2019-12-07 15:33:13
问题 Is it possible to use Byte Buddy to redefine a private method of a class? It seems that the entry point into using Byte Buddy is always sub-classing an existing class. When doing this, it is obviously not possible to redefine a private method of the parent class (at least not in a way that the redefined method is used in the parent class). Consider the following example: public class Foo { public void sayHello() { System.out.println(getHello()); } private String getHello() { return "Hello

How can I measure number of bytecode instructions in class file?

丶灬走出姿态 提交于 2019-12-07 15:26:24
问题 I have calculated the average cyclomatic complexity for each of my class files. I was wondering how I could measure the number of bytecode instructions in each of my class files using Eclipse perhaps? 回答1: I don't know if you can do that easily from Eclipse, but you can use javap -c to get a disassembly of your class files. Shouldn't be too hard to wrap that in a script if you only care about the number of instructions per method. Example: $ javap -c Test Compiled from "Test.java" public

How do I replace a class with new one with Java instrumentation?

元气小坏坏 提交于 2019-12-07 09:25:11
问题 I need to create a java agent that when is enabled it gets the path to a jar file as argument and then it replaces any loaded class the the one inside the jar file if their names are matched. For example, we have an application with a class called com.something.ClassTest. Now if the mentioned jar (is not in the class path) has a class exactly the same name as com.something.ClassTest, I want to replace it with the one in the jar. I have this class transformer but not sure if that's correct or

Is it possible to change a value inside a Lua bytecode? How? Any idea?

五迷三道 提交于 2019-12-07 08:50:48
问题 I got a script that is no longer supported and I'm looking for a way to change the value of a variable in it... The script is encrypted ( loadstring/bytecode/ something like that) e.g.: loadstring('\27\76\117\97\81\0\1\4\4\4\8\0\') I can find what I want to change (through notepad after I compile the script), but if I try to change the value, the script won't work, if I change and try to recompile it still won't work: "luac: Testing09.lua: unexpected end in precompiled chunk" ... Any ideas? I

invokestatic on static method in interface

女生的网名这么多〃 提交于 2019-12-07 05:23:35
问题 Disassembling some Java 8 code I found out that some invokestatic calls on static methods in interface (particularly this was java.util.function.Function.identity() ) uses InterfaceMethodRef in const pool; this is what javap -s -c -v p show me: 15: invokestatic #66 // InterfaceMethod java/util/function/Function.identity:()Ljava/util/function/Function; According to JVM 8 spec this is not possible, and when I've used this instruction in classfile with version Java 7 ( major version=51 ), it has

Java debugging with byte codes

旧时模样 提交于 2019-12-07 03:35:23
问题 I would like to know if there is any IDE or Eclipse Plugin that supports mixed mode debugging. As I searched the term mixed mode, found lot of references debugging VM languages alongside with native code. But I referring to a feature that is similar to the one available in compiled languages such as C where an user can see both C source line along side with the corresponding assembly line and will be able to step in even at assembly level. (please excuse If I had made a nomenclature mistake

How to count number of bytecodes executed in java

你说的曾经没有我的故事 提交于 2019-12-07 02:12:11
问题 I'm going to enter MIT's battlecode competition. The entrants write programs that control robots that fight each other. The catch is that your robots are limited to executing a certain amount of bytecode in a turn (last year it was 10000 per turn). Now, a simple loop like (int i=0; i<100; i++){ // do nothing } uses, according to their software, approximately 400 bytecode (presumably something like (2 bytecode for incrementing i plus 2 bytecode for checking if i<100) * 100 = 400 bytecode) so