bytecode-manipulation

Adding programmatic annotations to a Java class

不羁岁月 提交于 2019-12-10 04:10:07
问题 Usage example: I want to put on class fields a custom annotation @MyContainer and then add automatically on all such fields relevant Hibernate annotations (depending on field type and properties). In additional I need to add JAXB XmlType annotation to the class and base the type name on the class name. I would want additionally to add annotations to fields based on thier types, etc. All added annotations should be available at run time (So hibernate / JAXB can find them). I'm aware of the

Does JAXB use bytecode instrumentation?

試著忘記壹切 提交于 2019-12-10 03:00:50
问题 Someone where i work noticed (in stacktrace) that when running the jvm with -javaagent:spring-instrumentation.jar my JAXB annotated classes have strange new methods in them which we didn't write: e.g. SomeJaxbAnnotatedClass$JaxbAccessorM_getFields_setFields_java_util_Set.get Does this mean that jaxb uses bytecode instrumentation when it is available? Where can i read more about this functionality? Thanks, Yuval 回答1: Just an addition to skaffman's post: What you see (SomeJaxbAnnotatedClass

How can I remove some opcodes from Java class file?

放肆的年华 提交于 2019-12-08 18:43:30
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

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

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

Change string constant in a compiled class

…衆ロ難τιáo~ 提交于 2019-12-06 18:45:18
问题 I need to change a string constant in a deployed Java program, i.e. the value inside the compiled .class -files. It can be restarted, but not easily recompiled (though it's an inconvenient option if this question yields no answers). Is this possible? Update: I just looked at the file with a hex editor and it looks like I can easily change the string there. Would that work, i.e. won't that invalidate some kind of signature of the file? The old and new string are both alphanumeric, and can be

Java Bytecode Manipulation and Java reflection API? [closed]

我们两清 提交于 2019-12-06 15:45:41
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I recently came across the term "Bytecode manipulation" (what made to look into this, by chance I saw bytecode provider while seeing the logs in an application which used Hibernate) . I also know (a bit) about Java Reflection API. Are these two concepts similar? What are the

How can I run DataNucleus Bytecode Enhancer from SBT?

◇◆丶佛笑我妖孽 提交于 2019-12-06 03:33:12
I've put together a proof of concept which aims to provide a skeleton SBT multimodule project which utilizes DataNucleus JDO Enhancer with mixed Java and Scala sources. The difficulty appears when I try to enhance persistence classes from SBT. Apparently, I'm not passing the correct classpath when calling Fork.java.fork(...) from SBT. See also this question: How can SBT generate metamodel classes from model classes using DataNucleus? Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.datanucleus.util.Localiser at org.datanucleus.metadata

Differences in java bytecode produced by Oracle's and Eclipse's compilers

对着背影说爱祢 提交于 2019-12-05 16:48:16
问题 Our project does some Java bytecode instrumentation. And we stumbled upon some strange behavior. Suppose the following code snippet: public void a() { new Integer(2); } Oracle's javac compiles the above into the following bytecode: 0: new #2; //class java/lang/Integer 3: dup 4: iconst_2 5: invokespecial #3; //Method java/lang/Integer."<init>":(I)V 8: pop 9: return and Eclipse's compiler into: 0: new #15; //class java/lang/Integer 3: iconst_2 4: invokespecial #17; //Method java/lang/Integer."

java disassemble reassemble

邮差的信 提交于 2019-12-05 12:35:22
Say I want to take a java class file, disassemble it, tweak the java bytecode output, and then reassemble it again. I need to rename a symbol in the constant pool table. I also don't have access to the source code, and using a decompiler seems like overkill for this. I'm not trying to optimize anything - java does a fine job at that. Is there... a simple way to do this? I've found several tools for either disassembly or reassembly, but none for both; or no pairs of tools which seem to use the same format for representing the bytecode in text. Did you check the ASM API? Here is a code sample