bytecode

How to make a copy of a Java class in runtime?

£可爱£侵袭症+ 提交于 2019-12-14 03:47:49
问题 I have a class class Foo { int increment(int x) { return x + 1; } } I want to obtain a copy of this class in runtime, e. g. a class like class Foo$Copy1 { int increment(int x) { return x + 1; } } Which has all the same methods, but a different name. Proxy seem to help with delegating , but not copying the methods with all their bodies. 回答1: You can use Byte Buddy for this: Class<?> type = new ByteBuddy() .redefine(Foo.class) .name("Foo$Copy1") .make() .load(Foo.class.getClassLoader())

Using ASM to find generic signatures of “implicit” variables

て烟熏妆下的殇ゞ 提交于 2019-12-13 21:32:53
问题 I am building a dependency search tool using ASM 4.0 and I have found a corner case which I have been unable to solve. The problem I'm having has to do with identifing usages of MyClass in the code below. public void aMethod() { new ArrayList<? extends MyClass>(); } The usage of ArrayList can be identified using MethodVisitor.visitTypeInst(), but no signature method is available in that scope to identify the usage in the generic type parameter. MethodVisitor.visitLocalVariable() is not the

Java agent cannot transform all the classes in my project

只谈情不闲聊 提交于 2019-12-13 19:26:58
问题 Long story short: I need to transform every class in my program (even the java library that are loaded before my agent). I have find a way to do it but is not completly working. I'm open to new ideas. My actual method act strange: it's supposed to print the same names in file and console but they are not. I'm sure that those classes reach my transform method because if I try to instrument them I get an error. Complete story: I have created an agent in order to inject some custom code in every

getElementsByTagName(…).0.parentNode' is null or not an object

假如想象 提交于 2019-12-13 18:58:44
问题 I'm using Google Chart for my application and I have to convert the generated chart to image byte code . I've done this in Firefox and Chrome but IE8 is not responding to get the svg element , So now I can't to get the byte code from the given div element. My script to convert div element to byte code is given below function getElement() { for (var i = 0; i < divelement.length; i++) { toImg(document.getElementById(divelement[i]), i, medicalconditionid[i]); } } function toImg(chartContainer, i

how many places are optimized in Python's bytecode(version 2.5)

大兔子大兔子 提交于 2019-12-13 17:17:29
问题 Can anyone tell me how many places there are optimized in Python's bytecode? I was trying to de-compile Python's bytecode these days,but I found that in Python's version 2.5 there are a lot of optimization.For example: to this code a,b,c=([],[],[])#build list the non-optimized bytecode before version2.5 is like that: BUILD_LIST_0 BUILD_LIST_0 BUILD_LIST_0 BUILD_LIST_4 UNPACK_LIST_ STORE_NAME 'a' STORE_NAME 'b' STORE_NAME 'c' In the version2.5,the optimized bytecode is like this: BUILD_LIST_0

How to find an empty local variable in a method for instrumenting using asm library

喜夏-厌秋 提交于 2019-12-13 15:28:54
问题 While instrumenting a class for its different methods In order to make a method do a write operation in a text file. I first stored the string in a local variable 3160 explicitly defined. How to choose these variables to prevent conflicts with already existing variables. Like in this snippet The code does the work of writing the class name to a text file every time it enters any method. In order to do so the string s had to be loaded on stack using variable 3160 ( value kept large so that the

Editing a .class file directly, playing around with opcodes

本秂侑毒 提交于 2019-12-13 13:15:00
问题 today I just tried to play a little bit around with the opcodes in compiled java class file. After inserting iinc 1,1 the java virtual machine responds with: Exception in thread "main" java.lang.ClassFormatError: Truncated class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net

Is the hotspot JVM Bytecode Interpreter a tracing JIT?

 ̄綄美尐妖づ 提交于 2019-12-13 12:08:41
问题 The question pretty much says it all, I've been looking around for an answer even through the VM spec but I it doesn't explicitly state it. 回答1: No. There are some other JVMs with tracing JITs, though: HotPath and Maxine, for example. 回答2: Aside: for those who don't know what a tracing JIT is, the following description comes from this page: Although tracing JITs are a complex technology, the core concept is about optimizing execution of the hot paths in a program. The emphasis is specifically

Difference between byte code .<init>()V vs .<init>(Z)V

烈酒焚心 提交于 2019-12-13 11:41:46
问题 When I observe my Java project byte code, I see the following byte code : java.lang.Object.()V java.lang.Boolean.(Z)V What is the meaning of <init>()V and <init>(Z)V 回答1: java.lang.Object.()V is a void method ( V ) on java.lang.Object that takes no arguments. java.lang.Boolean.(Z)V is a void method on java.lang.Boolean that takes a single boolean ( Z since B is byte ) argument. In short, abc.def.WXYZ(IIIIIIIIIIIIII)J ^ ^ ^ target_class argument-types return_type See JNI Type Signatures for

how to debug an internal error?

自古美人都是妖i 提交于 2019-12-12 19:30:39
问题 So I have a class Foo that should eventually adjust and reload classes. It has a method for that, too: private void redefineClass(String classname, byte[] bytecode) { ClassFileLocator cfl = ClassFileLocator.Simple.of(classname,bytecode); Class clazz; try{ clazz = Class.forName(classname); }catch(ClassNotFoundException e){ throw new RuntimeException(e); } Debug._print("REDEFINING %s",clazz.getName()); new ByteBuddy() .redefine(clazz,cfl) .make() .load(clazz.getClassLoader(),