bytecode-manipulation

Attach proxy to an existing object?

点点圈 提交于 2019-12-12 10:44:47
问题 My plan is to write a annotation based caching framework which caches the return values of methods. When a method gets called the first time with a specific parameter, then the cache should store the methods return value. When the same method gets called a second time with the same parameter then the method should return the previously calculated result from the cache and not execute its code again. My annotations looks like this: @Cached(cacheProvider = HashMapCacheProvider.class) public

Is there Scala aware high level byte-code manipulation tool like Javassist?

馋奶兔 提交于 2019-12-12 10:29:16
问题 I am looking for a high level bytecode manipulation tool like Javassist, but that understands some of Scala peculiarities. Lower level bytecode manipulation tools should be relatively agnostic, but for my use cases something at the level of Javassist is much better. However a tool at that level needs to know about the source language and its bytecode mapping. Does something like this exist for Scala? So far I have been able to use Javassist with Scala for very simple things, but I have been

Java bytecode variable index 0's className is something strange

泪湿孤枕 提交于 2019-12-12 05:24:24
问题 I use ASM library to generate bytecodes and load them using Unsafe.defineAnonymous as a Class. Both work in most of cases, but after for a short time, it fails. Then I add some debug instructions in the emitted bytecodes to print something, and the output confused me for two weeks. (GWT is short for GuardWithTestHandle). 1, Two classes are generated: DYNGWT70 and DYNGWT73, and both are loaded using Unsafe . For each class, there is only one instance is created. 2, The layout of DYNGWT70 is

JDI, Java Byte code instrumentation and Java agents (JWDP, JVMTI)

一笑奈何 提交于 2019-12-11 04:38:17
问题 I am new in the realm of debuggers, instrumentation and JVMTI. So I have few questions about them. What is the difference between JDI(java debugger interface), JWDP, javaagent and native agent(JVMTI). and where does the java instrumentation API fit in picture. I am using JDI to intercept exceptions in target java application. but I found out that JDI is not good enough if we talk about how it impacts the performance of target app. I read that most good applications does this with combining

Few questions on generator expressions and speed efficient alternatives

允我心安 提交于 2019-12-11 03:58:44
问题 Consider the following code, integral to my questions below: import functools N = 3 class Struct: """Create an instance with argument=value slots. This is for making a lightweight object whose class doesn't matter.""" def __init__(self, **entries): self.__dict__.update(entries) def __repr__(self): args = ['%s=%s' % (k, repr(v)) for (k, v) in vars(self).items()] return '\nStruct(%s)' % ', '.join(args) def doit( move ): ( rowIn, colIn ) = move something = rowIn + ( 10 * colIn ) # An involved

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

半世苍凉 提交于 2019-12-11 03:42:23
问题 I want to add instructions to the code of methods. These instructions should be executed after reaching and before leaving the method. In order to make sure that the latter instructions are always executed before leaving I want to put these in a finally block. (I know the class AdviceAdapter but it does not ensure the execution of exit-code when an invoked method throws an exception.) My problem is that the instructions in the result are in the wrong order. Method to be processed: @Test

How to check bytecode length of java method

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:23:28
问题 At this moment I participate in big legacy project with many huge classes and generated code. I wish to find all methods that have bytecode length bigger than 8000 bytes (because OOTB java will not optimize it). I found manual way like this: How many bytes of bytecode has a particular method in Java? , however my goal is to scan many files automatically. I tried to use jboss-javassist, but AFAIK getting bytecode length is available only on class level. 回答1: Huge methods might indeed never get

identifying ``method code too large`` origin

空扰寡人 提交于 2019-12-10 19:10:41
问题 So I've run into MY: WARNING cannot transform class XYZ java.lang.RuntimeException: Method code too large! at org.objectweb.asm.MethodWriter.a(Unknown Source) at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source) at ... I am aware of Method code too large! exception using ASM and of the project it links to. However, I've been provided a modified version of ASM to work with and as such, using that project is not really an option. That will require my breaking up the offending methods

Can Scala 2.10 reflection emulate this Javassist functionality?

最后都变了- 提交于 2019-12-10 18:16:26
问题 I would like to know if it is possible to rewrite this function using Scala-2.10 reflection instead of Javassist: def adaptClass(name1: String, name2: String) : Class[_] = { import javassist._ val cls = ClassPool.getDefault().getAndRename(name1, name2) val field = CtField.make("private static final long serialVersionUID = 1L;", cls)) cls.addField(field, cls)) cls.toClass() } I am most interested in the part that adds a SerialVersionUID field to the new class, since that part of the above code

Selecting and modifying `if` statement with ASM

懵懂的女人 提交于 2019-12-10 17:54:03
问题 I want to update if statement in already existing class on particular line without changing the whole method. Here is the target code (names of classes, methods and some code changed because they're not relevant): public class Target extends Something { public Target(){ super(); //some code... } public Result targetMethod(Data firstPar, Data secondPar){ if(someStatement()) { return Result.FAIL; } else { if(firstPar.check()){ //here is the line I want to change firstPar.doSomething() }