bytecode-manipulation

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

Dynamic Bytecode Instrumentation fails without any error

北慕城南 提交于 2019-12-24 01:07:17
问题 Objective I'm doing dynamic bytecode instrumentation using a JVMTI agent. I have to instrument those methods which are "hot", that is, the methods which invoke JIT compiler. To do so I listen to a CompiledLoadEvent and inside its call back function, call RetransformClasses . This in turn invokes ClassFileLoadHook on the class containing "hot" function and actual instrumentation begins. Problem Premises Currently I'm instrumenting my class to spawn some threads. I also listen to thread starts

How to add a SerialVersionUID to a Class[_] instance in Scala?

有些话、适合烂在心里 提交于 2019-12-23 13:23:05
问题 I need to create an instances an instance of java.lang.Class that is otherwise identical to classOf[MyClass] but also has a SerialVersionUID , which MyClass does not have. MyClass is a Scala-2.10 class. One problem is that in Java SerialVersionUID is a static final while in Scala SerialVersionUID since Scala does not have statics. If MyClass was a Java class I think I would be able do this using Javassist: val ctclass = javassist.ClassPool.getDefault().get("mypackagage.MyClass") val field =

Bytecode manipulation patterns

大憨熊 提交于 2019-12-23 08:08:13
问题 What legitimate uses are there for bytecode manipulation and how people implement those bytecode manipulation based solutions in practice? Update: I should have made it more clear that this question really is about what patterns and techniques people use to make their code fly with the help of bytecode manipulation. Something like aspect oriented programming that was already mentioned or building proxy objects on the fly and similar techniques. 回答1: Bytecode manipulation lets you implement

Is it possible to do bytecode manipulation when using OSGi?

我怕爱的太早我们不能终老 提交于 2019-12-23 07:37:09
问题 I'm making an application server and in it I need to use some bytecode manipulation (e.g. inserting custom equals and hashCode methods to classes annotated with @Entity ). Now I give the JVM a Java Agent (the -javaagent option) which does bytecode transformations using ASM. I've been considering using OSGi, but I don't know whether it allows me to do the necessary bytecode manipulation. Is it possible to do bytecode manipulation when using OSGi? How? Is it possible for a bundle to declare

How can I remove some opcodes from Java class file?

为君一笑 提交于 2019-12-23 03:36:14
问题 Here are some code lines: // 43: invokevirtual 10 test/main:a (I)test/sub1; // 46: pop // 47: goto +4 -> 51 // 50: athrow // 51: aload_2 This is the byte code of a sample Java class file. I want to remove the opcodes of lines 47, 50... from java class file. How can I do this using ASM? 来源: https://stackoverflow.com/questions/11070680/how-can-i-remove-some-opcodes-from-java-class-file

Java Bytecode: Customized setter/getter with byte buddy

孤人 提交于 2019-12-22 08:30:17
问题 I am trying to create a "custom" setter method for a field with byte buddy. Buddy's own mechanism allows for standard setter/getter methods to be implemented very easily, however, I am looking for an elegant way to extend the setter with some additional logic. To simplify the example, let's assume we have a class A, which has a method setChanged(String). Goal is to make a sub-class of A, add a field with corresponding access methods. The catch is, that I want to call setChanged("fieldName")

How to copy resource files in classes folder with gradle?

烂漫一生 提交于 2019-12-22 06:56:55
问题 Enviroment I am using a third party lib which requires bytecode instrumentation. The tool which does the bytecode instrumentation requires some description files and those files have to be in the same folder structure like the compiled .class files. Those files are only necessary at compiletime. Problem I thought gradle would place all files (resource and class) temporarily within the same folder and then create a jar from that folder. But it seems that gradle have two different places for

Rewriting method calls within compiled Java classes

拥有回忆 提交于 2019-12-21 05:15:10
问题 I want to replace calls to a given class with calls to anther class within a method body whilst parsing compiled class files... or put another way, is there a method of detecting usages of a given class in a method and replacing just that part of the method using something like javaassist. for example.. if I had the compiled version of class A { public int m() { int i = 2; B.multiply(i,i); return i; } } is there a method of detecting the use of B and then altering the code to perform class A