bytecode

Fail-safe way of round-tripping JVM byte-code to text-representation and back

岁酱吖の 提交于 2019-12-06 08:38:21
问题 I'm looking for a fail-safe way to round-trip between a JVM class file and a text representation and back again. One strict requirement is that the resulting round-tripped JVM class file is exactly functionally equivalent to the original JVM class file as long as the text representation is left unchanged. Furthermore, the text representation must be human-readable and editable. It should be possible to make small changes to the the text representation (such as changing a text string or a

How to inspect the stack using an ASM visitor?

做~自己de王妃 提交于 2019-12-06 08:27:48
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 about the type of the variable. At the moment I really only need to look at what's at the top of the

Best choice? Edit bytecode (asm) or edit java file before compiling

ⅰ亾dé卋堺 提交于 2019-12-06 07:40:14
Goal Detecting where comparisons between and copies of variables are made Inject code near the line where the operation has happened The purpose of the code: everytime the class is ran make a counter increase General purpose: count the amount of comparisons and copies made after execution with certain parameters 2 options Note: I always have a .java file to begin with 1) Edit java file Find comparisons with regex and inject pieces of code near the line And then compile the class (My application uses JavaCompiler) 2)Use ASM Bytecode engineering Also detecting where the events i want to track

How to get rid of the unrelated classes when using WALA to analyze Java bytecode?

随声附和 提交于 2019-12-06 04:34:08
问题 I read the aricle about WALA on http://www.programcreek.com/2012/10/wala-tutorial/ and try to execute the example. I want to know how to get rid of the classes except my test code within test.jar. Thank you! import java.io.File; import java.io.IOException; import java.util.jar.JarFile; import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.cha

How are methods found in AVM2 bytecode?

允我心安 提交于 2019-12-06 03:36:09
问题 I've been playing around with ABC bytecode and was hoping someone could clear up a point of confusion for me. I have a simple flash file that places a clip on the stage and has a tiny script to update its position on each frame. The code looks something like: package { import flash.display.MovieClip; import flash.events.Event; public class RedCircle extends MovieClip { public function RedCircle() { this.addEventListener(Event.ENTER_FRAME, moveit); } function moveit(e:Event) { this.x -=1; } }

How does scala generated byte code drops the checked exception?

二次信任 提交于 2019-12-06 03:25:12
问题 If it possible to write byte code for a method that is supposed to throw a checked exception? For instance the following Java class doesn't compile unless the method declares it throws the checked exception: public class CheckedExceptionJava { public Class<?> testChecked(String s) throws ClassNotFoundException { return Class.forName(s); } } While the following Scala equivalent does ( because Scala doesn't have checked exceptions ) : class CheckedException { def testChecked( s : String ) =

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

落爺英雄遲暮 提交于 2019-12-06 02:55:15
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? 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 class Test extends java.lang.Object{ public Test(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang

Is it possible to explicitly free memory with JVM Bytecode?

允我心安 提交于 2019-12-06 01:51:05
问题 There are several computer programming languages using JVM bytecode as, lets say, target language for their interpreter/compilers. It seems to me that many new programming languages (less than 15 years old) run over JVM and I wonder whether explicit memory deallocation is forbidden for all of them: Is it possible to explicitly allocate-deallocate memory using in bytecode through any instruction? Is, on de contrary, the garbage collector always resposible for memory liberation? 回答1: The JVM

What's the difference between java bytecode astore_1 and astore_2

无人久伴 提交于 2019-12-05 22:37:04
What's the difference between java bytecode astore_1 and astore_2 ? The instructions astore_n , for small values of n , are just shorthand equivalents for astore n . Either version stores what's on top of the stack into local variable n . astore_1 is the same as astore 1 , and astore_2 is the same as astore 2 , except that astore_1 and astore_2 are one byte each, whereas astore is a two-byte instruction. 来源: https://stackoverflow.com/questions/6983641/whats-the-difference-between-java-bytecode-astore-1-and-astore-2

Can I redefine private methods using Byte Buddy?

≯℡__Kan透↙ 提交于 2019-12-05 21:40:30
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 World!"; } } Foo foo = new ByteBuddy() .subclass(Foo.class) .method(named("getHello")).intercept