bytecode

Why does the JVM have both `invokespecial` and `invokestatic` opcodes?

你。 提交于 2019-12-21 04:12:02
问题 Both instructions use static rather than dynamic dispatch. It seems like the only substantial difference is that invokespecial will always have, as its first argument, an object that is an instance of the class that the dispatched method belongs to. However, invokespecial does not actually put the object there; the compiler is the one responsible for making that happen by emitting the appropriate sequence of stack operations before emitting invokespecial . So replacing invokespecial with

Remapper variables during bytecode method inlining by ASM

核能气质少年 提交于 2019-12-20 20:43:12
问题 I am doing an online bytecode method inlining optimization using ASM. My changes are based on the example 3.2.6 Inline Method (http://asm.ow2.org/current/asm-transformations.pdf). The test example (inline callee's calculate(int,int) at Caller::test) is: public class Caller { final Callee _callee; public Caller(Callee callee){ _callee = callee; } public static void main(String[] args) { new Caller(new Callee("xu", "shijie")).test(5, 100); } public void test(int a, int b){ int t = a; int p = b;

JVM instruction ALOAD_0 in the 'main' method points to 'args' instead of 'this'?

微笑、不失礼 提交于 2019-12-20 17:25:46
问题 I am trying to implement a subset of Java for an academic study. Well, I'm in the last stages (code generation) and I wrote a rather simple program to see how method arguments are handled: class Main { public static void main(String[] args) { System.out.println(args.length); } } Then I built it, and ran 'Main.class' through an online disassembler I found at: http://www.cs.cornell.edu/People/egs/kimera/disassembler.html I get the following implementation for the 'main' method: (the

JVM instruction ALOAD_0 in the 'main' method points to 'args' instead of 'this'?

一个人想着一个人 提交于 2019-12-20 17:25:12
问题 I am trying to implement a subset of Java for an academic study. Well, I'm in the last stages (code generation) and I wrote a rather simple program to see how method arguments are handled: class Main { public static void main(String[] args) { System.out.println(args.length); } } Then I built it, and ran 'Main.class' through an online disassembler I found at: http://www.cs.cornell.edu/People/egs/kimera/disassembler.html I get the following implementation for the 'main' method: (the

Can you inspect the byte code of a Java 8 lambda at runtime?

喜夏-厌秋 提交于 2019-12-20 08:59:30
问题 If you have an anonymous class like Predicate<String> isEmpty = new Predicate<String>() { public boolean test(String t) { return t.isEmpty(); } }; A library which is passed the reference to isEmpty can inspect the byte code to see what it does and possibly manipulate it. Is there a way you can do this for lambdas? Predicate<String> isEmpty = String::isEmpty; e.g Say have this code and byte code public class Main { public static void test(Predicate<String> tester) { System.out.println("tester

How to change static variable value using ASM?

女生的网名这么多〃 提交于 2019-12-20 05:53:37
问题 I started learning Java Agent few days ago. But documentation is not very good and beginners like me struggling to understand the basics. I created a basic multiplier class and export it to runnable jar using eclipse. Here is the code snippet. Main jar file: public class Multiplier { public static void main(String[] args) { int x = 10; int y = 25; int z = x * y; System.out.println("Multiply of x*y = " + z); } } Bytecode for above class Now I want to manipulate the value of x from an agent. I

Is Java byte code compiled in JDK 6 and runs on JDK7 open to vulnerability fixed in JDK 7?

别来无恙 提交于 2019-12-20 05:32:06
问题 The motivation of my question is simple: Unfortunately Oracle stopped development of Java 6 and will not provide any additional build. If Oracle will discover any security issue they will fix it only in Java 7. We have big project that developed in Java 6 and I do not have resources to convert it to Java 7. So, I want to compile the code in last build of JDK 6 (6u45) and to run it in most updated build of JDK 7. Is in this case my byte code will be open to vulnerability fixed in JDK 7? Added

Is Java byte code compiled in JDK 6 and runs on JDK7 open to vulnerability fixed in JDK 7?

梦想的初衷 提交于 2019-12-20 05:32:05
问题 The motivation of my question is simple: Unfortunately Oracle stopped development of Java 6 and will not provide any additional build. If Oracle will discover any security issue they will fix it only in Java 7. We have big project that developed in Java 6 and I do not have resources to convert it to Java 7. So, I want to compile the code in last build of JDK 6 (6u45) and to run it in most updated build of JDK 7. Is in this case my byte code will be open to vulnerability fixed in JDK 7? Added

Wrong Stack Size calculated by ASM library

风格不统一 提交于 2019-12-20 05:15:34
问题 I generate bytecodes using ASM library and 'Max stack size' for a method is left to be calculated automatically. During runtime,i found this value (max stack size) is not correct. My source code is: ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); .... MethodType initType = MethodType.methodType(void.class, clsList); mv = cw.visitMethod(ACC_PUBLIC, "<init>", initType.toMethodDescriptorString(), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL

Change behaviour of static method in Java - byte code manipulation

岁酱吖の 提交于 2019-12-20 02:59:12
问题 I am trying to manipulate a static method. For this, Byte Buddy or any other framework can be used. There is one library that is called Pi4J that is used for controlling GPIO of Raspberry Pi. This library has a method called: GpioController gpio = GpioFactory.getInstance(); And this call is called in several places of a program that I might not have control such that I need to modify the invocation. What I would like to do is that when GpioFactory.getInstance is executed in some way detect