byte-buddy

How to create a dynamic proxy using ByteBuddy

▼魔方 西西 提交于 2020-02-22 06:48:30
问题 In Java it is possible to create dynamic proxies using an implementation of InvocationHandler . Despite JVM optimizations, using reflection will always have some overhead invoking a method. To try to solve this problem, I tried to use ByteBuddy to create the proxy classes at runtime, but the documentation didn't seem clear enough on this aspect. How do I create a MethodCallProxy in order to forward a method invocation to some class instance? Edit: To better clarify my problem, I am providing

How to create a dynamic proxy using ByteBuddy

点点圈 提交于 2020-02-22 06:47:57
问题 In Java it is possible to create dynamic proxies using an implementation of InvocationHandler . Despite JVM optimizations, using reflection will always have some overhead invoking a method. To try to solve this problem, I tried to use ByteBuddy to create the proxy classes at runtime, but the documentation didn't seem clear enough on this aspect. How do I create a MethodCallProxy in order to forward a method invocation to some class instance? Edit: To better clarify my problem, I am providing

How to take the exception thrown by a constructor using a ByteBuddy agent?

て烟熏妆下的殇ゞ 提交于 2020-02-04 03:46:07
问题 I'm trying to log every call, returned objects and exceptions thrown in methods and constructors using a ByteBuddy (v1.7.9) java agent, without iterfering with the normal functioning of the instrumented code. My current instantiation of the agent is new AgentBuilder.Default() .with(AgentBuilder.Listener.StreamWriting.toSystemOut()) .type((typeDescription, classLoader, module, classBeingRedefined, protectionDomain) -> matcher.matchesIncoming(typeDescription.getTypeName())) .transform((builder,

Java Agent using Byte-Buddy doesn't work

心已入冬 提交于 2020-01-16 05:35:52
问题 I need your help in finding what's wrong with my implementation... I'm trying to implement a simple JVM runtime profiler using byte-buddy. In general, what I need is that every method call will be logged in a stack which I manage in a separate object. After reading several posts, I understood that it's better to use the "Advise" approach instead of "MethodDelegation", and here's what I came out with: Agent.java: package com.panaya.java.agent; import net.bytebuddy.agent.builder.AgentBuilder;

Java Agent using Byte-Buddy doesn't work

限于喜欢 提交于 2020-01-16 05:35:42
问题 I need your help in finding what's wrong with my implementation... I'm trying to implement a simple JVM runtime profiler using byte-buddy. In general, what I need is that every method call will be logged in a stack which I manage in a separate object. After reading several posts, I understood that it's better to use the "Advise" approach instead of "MethodDelegation", and here's what I came out with: Agent.java: package com.panaya.java.agent; import net.bytebuddy.agent.builder.AgentBuilder;

Can I instrument outgoing method/constructor calls with ByteBuddy?

℡╲_俬逩灬. 提交于 2020-01-07 04:00:51
问题 I have a project where I was using Javassist to log outgoing method/constructor calls with code like this: CtMethod cm = ... ; cm.instrument( new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { if (m.getClassName().equals("Point") && m.getMethodName().equals("move")) m.replace("{ $1 = 0; $_ = $proceed($$); }"); } }); which assigns '0' to the first argument of the called method and then proceeds with the original call, that is, if cm represents the method

Instrument in java level using byte-buddy

℡╲_俬逩灬. 提交于 2020-01-06 05:10:14
问题 I have a code for Thread Pool example as follows public class RunThreads{ static final int MAX_TASK = 3; public static void main(String[] args) { Runnable r1 = new Task("task 1"); Runnable r2 = new Task("task 2"); Runnable r3 = new Task("task 3"); Runnable r4 = new Task("task 4"); Runnable r5 = new Task("task 5"); ExecutorService pool = Executors.newFixedThreadPool(MAX_TASK); pool.execute(r1); pool.execute(r2); pool.execute(r3); pool.execute(r4); pool.execute(r5); pool.shutdown(); }} and

Byte Buddy - java.lang.NoSuchMethodException - what is the correct defineMethod syntax?

痴心易碎 提交于 2020-01-05 07:22:38
问题 I am trying to create a setter and a getter for a field using Byte Buddy. public class Sample { public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException, NoSuchMethodException { Class<?> type = new ByteBuddy() .subclass(Object.class) .name("domain") .defineField("id", int.class, Visibility.PRIVATE) .defineMethod("getId", int.class, Visibility.PUBLIC).intercept(FieldAccessor.ofBeanProperty()) .make() .load(Sample

ASM - strange localVar index using newLocal from LocalVariableSorter

徘徊边缘 提交于 2020-01-04 09:22:43
问题 I'm adding new locals via newLocal from LocalVariableSorter . The method I'm adding the locals to is an instance method with a long parameter. I'm adding two locals; one long, one object. There are no other local vars in the sample code. As a result I would have expected the following slots / indexes: 0 - this 1 - the long param 3 - my 1st local added via `newLocal` - using two slots as it is a long 5 - my 2nd local added via `newLocal` What I do get as return from newLocal is 3 and 7 though.

Byte Buddy 1.9.x throws `java.lang.IllegalStateException: Cannot resolve type description for java.lang.String` errors. Is it a known issue?

有些话、适合烂在心里 提交于 2020-01-03 05:31:05
问题 I am seeing Cannot resolve type description errors when trying to load classes instrumented using Byte Buddy v1.9.11 within Mule 4 (JDK 1.8). Is there a known issue with Byte Buddy, or a particular combination of isolated classloader Mule 4 is using with Byte Buddy instrumented classes? Any suggestions are appreciated. I am using Elastic Java APM agent to instrument Mule 4 with its over-complicated classloader isolation mechanism that seems to interfere with Byte Buddy v1.9.11 used by the APM