bytecode-manipulation

How to copy resource files in classes folder with gradle?

守給你的承諾、 提交于 2019-12-05 11:46:23
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 resources and class files before assembling a jar. Like mentioned before the third party tool for code

invokestatic on static method in interface

空扰寡人 提交于 2019-12-05 10:33:32
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 thrown VerifyError on this instruction. However, when I've changed the major version to 52 , it

Add field to Proxy class created with Javassist

▼魔方 西西 提交于 2019-12-05 06:09:39
问题 I am creating a Proxy class using Javassist ProxyFactory with the following code: ProxyFactory factory = new ProxyFactory(); factory.setSuperclass(entity.getClass()); factory.setInterfaces(new Class[] { MyCustomInterface.class }); ..... Class clazz = factory.createClass(); Object result = clazz.newInstance(); The problem is that I also need to add a field to the class. But if I do CtClass proxy = ClassPool.getDefault().get(clazz.getName()); it gaves a NotFoundException How can I add a field

Where does bytecode injection happen?

為{幸葍}努か 提交于 2019-12-05 04:43:14
问题 Motivation I have a SomeObject.java file: class SomeObject { String name; } Compiling it creates a bytecode-containing SomeObject.class file. 0xCAFEBABE... If we use SomeObject on the JVM, it is loaded by the current classloader and all works fine. Now let's assume that I'd like to have some dynamic code generation. I can write my custom annotation @Target(ElementType.TYPE) public @interface Data { ... } and add it as a modifier to the class declaration: @Data class SomeObject { String name;

Does JAXB use bytecode instrumentation?

无人久伴 提交于 2019-12-05 03:00:27
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 Just an addition to skaffman's post: What you see (SomeJaxbAnnotatedClass$JaxbAccessor...) is an inner class, which is generated dynamically by the JAXB reference implementation. To

Java Bytecode Manipulation and Java reflection API? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-04 22:45:16
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 difference between them? When to use which? Reflection API allows you to access the information about the

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

耗尽温柔 提交于 2019-12-04 01:10:22
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."<init>":(I)V 7: return As you can see, Oracle compiler produces "dup" after "new", whereas Eclipse doesn

Where does bytecode injection happen?

家住魔仙堡 提交于 2019-12-03 21:12:30
Motivation I have a SomeObject.java file: class SomeObject { String name; } Compiling it creates a bytecode-containing SomeObject.class file. 0xCAFEBABE... If we use SomeObject on the JVM, it is loaded by the current classloader and all works fine. Now let's assume that I'd like to have some dynamic code generation. I can write my custom annotation @Target(ElementType.TYPE) public @interface Data { ... } and add it as a modifier to the class declaration: @Data class SomeObject { String name; } I can also retain it for the runtime with @Retention(RetentionPolicy.RUNTIME) : @Retention

Stand-alone Bytecode Verifier

橙三吉。 提交于 2019-12-03 18:00:03
问题 In my bytecode instrumentation project, I stumble frequently on VerifyErrors. However, the default java Verifier gives little information on which instruction resulted in the error (it only gives the method and a small message). Is there any stand-alone bytecode verifier which provides with a little more advanced help in locating the error, at least the precise instruction location? Thank you. 回答1: As with any project involving JVM bytecode, I would first check to see whether the BCEL has

native java bytecode instrumentation

孤者浪人 提交于 2019-12-03 16:36:53
for bytecode instrumentation in java, there is the asm framework and the bcel and javaassist libraries. However I need to do instrumentation in native code, since some java classes are already loaded by the time the javaagent runs, eg java.lang.Thread, java.lang.Class, etc is there any library for instrumenting java classes in native code? Edit: Seems there is a bit of confusion. What I want is: Create a native java agent, which uses JVMTI apis to change the bytecode of a class while its being loaded, using the OnClassLoad event hook. I encountered this problem during my doctoral research. The