jvm-bytecode

How to copy InsnList

拜拜、爱过 提交于 2019-12-11 06:06:21
问题 InsnList has no method for copy self. I tried to iterate list and add each node to new list. But iterating copy of list perform npe private static InsnList copy(InsnList insnList) { InsnList r = new InsnList(); for (int i = 0; i < insnList.size(); i++) r.add(insnList.get(i)); return r; } InsnList copy = copy(someList); for (int i = 0; i < copy.size(); i++) System.out.println(copy.get(i)); I expected that copy will be, but iterating of copy produce follow error Exception in thread "main" java

How To Modify Constant Pool Using ASM?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:24:13
问题 I already understand how to manipulate a class on runtime using ASM from this post. But I have further question regarding how to modify the constant pool. Below is a sample java program that I want modify Main jar file: public class test { private static final String a = "Hello World"; private static final String b = "ASM is awasome"; public static void main(String[] args) { int x = 10; int y = 25; int z = x * y; System.out.println(a); System.out.println(z); System.out.println(b); } } I want

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

How can this code use reserved keywords as field names?

前提是你 提交于 2019-12-11 01:44:48
问题 I found the following construction in legacy java bytecode while trying to troubleshoot server application startup. My IDE decompiled some third party libraries and I'm curious how this can be valid - never saw before keywords can be used as field names in bytecode. Bytecode version is 48.0 (Java 1.4). public final class f implements UserContext{ private final String try; private final UserInfo do; // a lot of code here public UserInfo getUserInfo(){ return this.do; } public String

Can I recompile a public API with a sub-interface and keep binary compatibility?

半城伤御伤魂 提交于 2019-12-10 18:14:45
问题 I have a public API, used several times across several projects: public interface Process<C extends ProcessExecutionContext> { Future<?> performAsync(C context); } And an abstract class that takes care of implementing the Future mechanism (not shown). I know that all projects subclass the corresponding abstract class (for which performAsync is final ) and no single class implements the abstract interface without subclassing the abstract implementor. This is by design and because this "public"

ASM Try/Catch Block with an output value

只谈情不闲聊 提交于 2019-12-10 10:46:34
问题 I am currently trying make my custom compiler allow using try/catch as an expression, i.e. leaving a value on the stack. The type checker and the backend already support this, but the problem seems to be ASM's COMPUTE_FRAMES . With the below code for instrumentation: private void write(MethodWriter writer, boolean expression) { org.objectweb.asm.Label tryStart = new org.objectweb.asm.Label(); org.objectweb.asm.Label tryEnd = new org.objectweb.asm.Label(); org.objectweb.asm.Label endLabel =

Status of JSR/RET in JVM spec

时间秒杀一切 提交于 2019-12-10 02:50:04
问题 There are some parts of the JVM specification which suggest that the operations JSR (Jump SubRoutine), JSR_W (Jump SubRoutine Wide) and RET (RETurn from subroutine) may be used only up to class file version 50.0 (JDK 1.6): 3.13 Compiling Finally (This section assumes a compiler generates class files with version number 50.0 or below, so that the jsr instruction may be used. See also §4.10.2.5.) And later: 4.10.2.5. Exceptions and finally To implement the try - finally construct, a compiler

Java bytecode decompiler in IntelliJIDEA for Scala

独自空忆成欢 提交于 2019-12-09 09:18:35
问题 I'm using IntellijIDEA Ultimate Edition. Browsing .class files that compiled from java source code is easy: I can just double-click on .class file and IDEA will decompile it. However, with .class files that were compiled from scala source code it's not working. It seems that IDEA just referencing to the scala source file. I've noticed that IDEA behaves like that only with scala plugin installed. It works fine without it. Is there a way to decompile using IDEA without switching off scala

Get MethodHandle from lambda object

萝らか妹 提交于 2019-12-08 21:00:35
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 name (or a handle to) the implementation method? Alternately, given a list of implementation methods,

Why does java bytecode “store” often followed by “load”?

会有一股神秘感。 提交于 2019-12-08 18:12:43
问题 When I read jvm bytecode which from some small java function, I found that when a new local variable is caculated on the operand stack, assuming that it will be stored in the local variable table, but usually it will be loaded to the operand stack immediately (just in the terms of bytecode literally). I don't understand the operation well, is it unnecessary operation? 回答1: The Java compiler tends to compile things in a very simple and straightforward manner, leaving optimization to the JIT.