java-bytecode-asm

ASM (from ObjectWeb) not calculating MaxStack correctly even though ClassWriter( COMPUTE_MAX + COMPUTE_STACK ) is set

本小妞迷上赌 提交于 2020-01-05 04:31:06
问题 I am getting expected ClassVerifyErrors when attempting to load a class i have generated using ASM. On further inspection i can see that the jvm is correct and that the method is talking about has an invalid MAX_STACK value. THe strange thing is am using the auto calculate the stack and max local options so this should not be a problem... The method with the invalid option is very simple and yet the result is bad bytecode. I have written a class with the intended method and compared my asm

ASM - strange localVar index using newLocal from LocalVariableSorter

徘徊边缘 提交于 2020-01-04 09:22:43
问题 I'm adding new locals via newLocal from LocalVariableSorter . The method I'm adding the locals to is an instance method with a long parameter. I'm adding two locals; one long, one object. There are no other local vars in the sample code. As a result I would have expected the following slots / indexes: 0 - this 1 - the long param 3 - my 1st local added via `newLocal` - using two slots as it is a long 5 - my 2nd local added via `newLocal` What I do get as return from newLocal is 3 and 7 though.

How to create a local variable with ASM?

余生颓废 提交于 2020-01-04 06:49:51
问题 I'm trying to patch a class with ASM. I need to add some logic in a function. This logic needs a new local variable. Here is what I've done: class CreateHashTableMethodAdapter extends MethodAdapter { @Override public void visitMethodInsn(int opcode, String owner,String name, String desc){ System.out.println(opcode + "/" + owner + "/" + name + "/" + desc); if(opcode == Opcodes.INVOKESPECIAL && "javax/naming/InitialContext".equals(owner) && "<init>".equals(name) && "()V".equals(desc)){ System

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

自作多情 提交于 2020-01-02 07:11:21
问题 Some time ago, I asked in Embed the existing code of a method in a try-finally block how to wrap the body of a method in a try-finally block using ASM. The solution was to visit a label for the try block at the beginning of the method body in visitCode() and to complete the try-finally block when visiting an instruction with a return opcode in visitInsn() . I was aware that the solution won't be working if a method has no return instruction which applies if the method is always leaving with

Java ASM Bytecode Modification-Changing method bodies

六眼飞鱼酱① 提交于 2019-12-31 22:21:11
问题 I have a method of a class in a jar whose body I want to exchange with my own. In this case I just want to have the method print out "GOT IT" to the console and return true; I am using the system loader to load the classes of the jar. I am using reflection to make the system classloader be able to load classes by bytecode. This part seems to be working correctly. I am following the method replacement example found here: asm.ow2.org/current/asm-transformations.pdf. My code is as follows:

Java find out what imports a .class has [duplicate]

二次信任 提交于 2019-12-25 05:14:25
问题 This question already has answers here : How to get all imports defined in a class using java reflection? (3 answers) Closed 2 years ago . Is there a way to find out what imports a class has? In this question: Jon Skeet says that you can't do this using reflection, but If you want to find all the types used within the compiled code, that's a slightly different matter. You may want to look at BCEL as a way of analyzing bytecode. This is what I want to know how to do. 回答1: Here is an old

Java count individual bytecode instructions executed

China☆狼群 提交于 2019-12-24 10:56:44
问题 I am trying to use ASM to count the individual bytecode instructions executed within a single function to build a histogram. I see there is a tool ByCounter that can do a similar task--but I do not have access to the source code. My understanding is the Java asm bytecode library can instrument classes, fields, methods, but examples for instrumenting an individual bytecode instruction are not to be found (though from ByCounter--it is found to be possible). If a tool like the JVMTI is better

ASM transformation to find concrete class type

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 10:46:39
问题 I'm working on a project that will trace method calls from a class within a package to any other class. It's important that I can identify concrete types, and I'd prefer to have a minimum tracing overhead. There is no restrictions on when the probe is triggered; it can be before or after a method has been called. ASM is currently used, but there is no requirement for it. The system is moving from AspectJ in order to allow dynamic attachment, so that's out. Below is the current situation. A

is it possible to remove jumps with final boolean on java jit?

空扰寡人 提交于 2019-12-24 03:48:12
问题 As we know some people say java JIT is faster then C++. I had some idea to utilize JIT and remove some instructions at runtime code. Here is sample code i tried: /** * Created by kadirbasol on 4/6/14. */ public class RemoveJump { public final boolean test; private static RemoveJump instance = new RemoveJump(); public static final RemoveJump getInstance() { return instance; } private RemoveJump() { //set the test on the constructor once and //remove this if statement forever from testLoop test

Constructor bytecode

扶醉桌前 提交于 2019-12-24 01:12:59
问题 The ASM guide talks about constructors: package pkg; public class Bean { private int f; public int getF() { return this.f; } public void setF(int f) { this.f = f; } } The Bean class also has a default public constructor which is generated by the compiler, since no explicit constructor was defined by the programmer. This default public constructor is generated as Bean() { super(); } . The bytecode of this constructor is the following: ALOAD 0 INVOKESPECIAL java/lang/Object <init> ()V RETURN