java-bytecode-asm

Embed the existing code of a method in a try-finally block

半世苍凉 提交于 2019-12-11 03:42:23
问题 I want to add instructions to the code of methods. These instructions should be executed after reaching and before leaving the method. In order to make sure that the latter instructions are always executed before leaving I want to put these in a finally block. (I know the class AdviceAdapter but it does not ensure the execution of exit-code when an invoked method throws an exception.) My problem is that the instructions in the result are in the wrong order. Method to be processed: @Test

java.lang.VerifyError: Expecting a stackmap frame occuring with ASM generated byte code

自闭症网瘾萝莉.ら 提交于 2019-12-11 00:34:00
问题 I generated java byte code in main.class as follows using ASM 5.0. Here is the code I've generated: javap -c _main.class output public jcalc.lang.CalcObject call(); Code: 0: ldc #9 // String _main/max 2: invokestatic #28 // Method jcalc/lang/Binding.getBindingFromMain:(Ljava/lang/String;)Ljcalc/lang/Binding; 5: ldc #20 // String A 7: invokevirtual #38 // Method jcalc/lang/Binding.refVariable:(Ljava/lang/String;)Ljcalc/lang/CalcObject; 10: checkcast #40 // class jcalc/lang/CalcNumber 13: ldc

identifying ``method code too large`` origin

空扰寡人 提交于 2019-12-10 19:10:41
问题 So I've run into MY: WARNING cannot transform class XYZ java.lang.RuntimeException: Method code too large! at org.objectweb.asm.MethodWriter.a(Unknown Source) at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source) at ... I am aware of Method code too large! exception using ASM and of the project it links to. However, I've been provided a modified version of ASM to work with and as such, using that project is not really an option. That will require my breaking up the offending methods

Selecting and modifying `if` statement with ASM

懵懂的女人 提交于 2019-12-10 17:54:03
问题 I want to update if statement in already existing class on particular line without changing the whole method. Here is the target code (names of classes, methods and some code changed because they're not relevant): public class Target extends Something { public Target(){ super(); //some code... } public Result targetMethod(Data firstPar, Data secondPar){ if(someStatement()) { return Result.FAIL; } else { if(firstPar.check()){ //here is the line I want to change firstPar.doSomething() }

ASM Try/Catch Block with an output value

只谈情不闲聊 提交于 2019-12-10 10:46:34
问题 I am currently trying make my custom compiler allow using try/catch as an expression, i.e. leaving a value on the stack. The type checker and the backend already support this, but the problem seems to be ASM's COMPUTE_FRAMES . With the below code for instrumentation: private void write(MethodWriter writer, boolean expression) { org.objectweb.asm.Label tryStart = new org.objectweb.asm.Label(); org.objectweb.asm.Label tryEnd = new org.objectweb.asm.Label(); org.objectweb.asm.Label endLabel =

Trying to install eclipse Bytecode Outline plugin, missing dependency

倖福魔咒の 提交于 2019-12-10 10:17:34
问题 I'm trying to install this: http://asm.ow2.org/eclipse/index.html, but I get this error which makes zero sense to me. I'm running eclipse Kepler Service Release 1, build id 20130919-0819. Cannot complete the install because one or more required items could not be found. Software being installed: Bytecode Outline 2.1.0 (de.loskutov.BytecodeOutline.feature.feature.group 2.1.0) Missing requirement: Bytecode Outline 2.1.0 (de.loskutov.BytecodeOutline.feature.feature.group 2.1.0) requires 'org

Compile Error: JSR/RET are not supported with computeFrames option

孤人 提交于 2019-12-08 19:12:13
问题 Getting this error on an IntelliJ project when I compile java files. There is no specific source file listed, but it fails with this error. Removing the following compiler flags fixes the error: -source 1.5 -target 1.5 However, these need to be in there as we are targeting Java 5. Is there some specific code (maybe a try/catch block) that is causing this error? 2013-10-15 16:21:50,556 [26947209] INFO - ompiler.BackendCompilerWrapper - JSR/RET are not supported with computeFrames option java

How to get the return value in asm?

怎甘沉沦 提交于 2019-12-08 13:57:47
问题 I want to extract the return value that type is org.apache.commons.dbcp.BasicDataSource How can I achieve this in asm? I have to get the instance of the class, org.apache.commons.dbcp.BasicDataSource right after it is created in createDataSource(). So I will visit this method and put some bytecode for getting the return value. 回答1: I used Advice Adapter to get the return value from a method. A method either return a value or throw exception.Hope below code helps you. import org.objectweb.asm

Modifiying <clinit> with ASM

安稳与你 提交于 2019-12-08 11:22:48
问题 Hello I have a little problem with ASM. It produces a class with bytecode error: Exception in thread "main" java.lang.VerifyError: Bad instruction Exception Details: Location: me/test/Main.<clinit>()V @0: wide Reason: Error exists in the bytecode at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod

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

馋奶兔 提交于 2019-12-08 02:56:13
问题 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