jvm-bytecode

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

Get MethodHandle from lambda object

徘徊边缘 提交于 2020-01-14 04:03:27
问题 From java.lang.invoke.LambdaMetafactory: The recommended mechanism for evaluating lambda expressions is to desugar the lambda body to a method, invoke an invokedynamic call site whose static argument list describes the sole method of the functional interface and the desugared implementation method, and returns an object (the lambda object) that implements the target type. And from inspection this is at least what Oracle JDK does. My question: given a lambda object is there a way to find the

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.

Constructor bytecode

扶醉桌前 提交于 2019-12-24 01:12:59
问题 The ASM guide talks about constructors: package pkg; public class Bean { private int f; public int getF() { return this.f; } public void setF(int f) { this.f = f; } } The Bean class also has a default public constructor which is generated by the compiler, since no explicit constructor was defined by the programmer. This default public constructor is generated as Bean() { super(); } . The bytecode of this constructor is the following: ALOAD 0 INVOKESPECIAL java/lang/Object <init> ()V RETURN

Variable 'final' modifier lost in Bytecode?

我的梦境 提交于 2019-12-23 08:57:08
问题 Analyzing the bytecode of this simple class, I have come to the conclusion that the compiler doesn't retain any information about a local variable being final . This seems weird though, since I believe the HotSpot compiler could actually use this information to do optimizations. Code : public static void main(String[] args) { final int i = 10; System.out.println(i); } Bytecode : public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code:

Reversed if condition in java bytecode

大兔子大兔子 提交于 2019-12-23 07:25:44
问题 Consider simple example private static String isPositive(int val) { if (val > 0) { return "yes"; } else { return "no"; } } Here it's pretty straightforward: if val > 0 return yes else return no . But after compilation, in bytecode, this if condition is reversed: private static isPositive(I)Ljava/lang/String; L0 LINENUMBER 12 L0 ILOAD 0 IFLE L1 L2 LINENUMBER 13 L2 LDC "yes" ARETURN L1 LINENUMBER 15 L1 FRAME SAME LDC "no" ARETURN It checks: if val <= 0 then return no , else return yes . First,

Reversed if condition in java bytecode

谁说我不能喝 提交于 2019-12-23 07:25:17
问题 Consider simple example private static String isPositive(int val) { if (val > 0) { return "yes"; } else { return "no"; } } Here it's pretty straightforward: if val > 0 return yes else return no . But after compilation, in bytecode, this if condition is reversed: private static isPositive(I)Ljava/lang/String; L0 LINENUMBER 12 L0 ILOAD 0 IFLE L1 L2 LINENUMBER 13 L2 LDC "yes" ARETURN L1 LINENUMBER 15 L1 FRAME SAME LDC "no" ARETURN It checks: if val <= 0 then return no , else return yes . First,

Inserting to InsnList before several nodes

醉酒当歌 提交于 2019-12-23 02:56:11
问题 I am trying to: 1) Iterate instructions and find all relevant nodes 2) Insert custom code before found nodes I used streams and iterator to make it and insert, which works only for the first node InsnList instructions = methodNode.instructions; InsnList addition = ... //It work: found n nodes for n return instructions Stream<AbstractInsnNode> returnNodes = Stream.iterate(instructions.getFirst(), AbstractInsnNode::getNext).limit(instructions.size()) .filter(n -> returnOpcodes.contains(n

Why is there no ICMP instruction?

给你一囗甜甜゛ 提交于 2019-12-22 08:13:30
问题 As some of you might know, we have a ton of opcodes for comparing different types of primitive values: LCMP FCMPL FCMPG DCMPL DCMPG IFEQ IFNE IFLT IFGE IFGT IFLE IF_ICMPEQ IF_ICMPNE IF_ICMPLT IF_ICMPGE IF_ICMPGT IF_ICMPLE IF_ACMPEQ IF_ACMPNE ... For obvious reasons the creators of the instruction set did not bother to add all IF_LCMPEQ , IF_FCMPLT , ... instructions, but I am wondering why there is no ICMP instruction, seeing that it would be very useful especially for booleans or Integer

Kotlin inlined extension property

无人久伴 提交于 2019-12-22 04:37:07
问题 I know inline keyword means to avoid the call overhead calling a funtion. But I can't figure out what inline a extension property work for? Let say we have two extension property named foo and another with is inlined named bar val Any.foo : Long get() = Date().time inline val Any.bar : Long get() = Date().time Executing any of them, we gent the expected output, the current time. The bytecode for this file is this below: public final class InlinedExtensionPropertyKt { public final static