What is a stack map frame

Java requires all classes that are loaded to be verified, in order to maintain the security of the sandbox and ensure that the code is safe to optimize. Note that this is done on the bytecode level, so the verification does not verify invariants of the Java language, it merely verifies that the bytecode makes … Read more

ASM Get exact value from stack frame

Your code ignores the benefits of Java 5 almost completely. When you update it, you’ll get for(MethodNode mn: cn.methods) { if(!mn.name.equals(“main”)) continue; Analyzer<BasicValue> analyzer = new Analyzer<>(new BasicInterpreter()); analyzer.analyze(cn.name, mn); int i = -1; for (Frame<BasicValue> frame: analyzer.getFrames()) { i++; if(frame == null) continue; int opcode = mn.instructions.get(i).getOpcode(); if(opcode != Opcodes.ILOAD) continue; BasicValue stackValue = frame.getStack(0); … Read more

is it possible to disable javac’s inlining of static final variables?

Item 93 of Java Puzzlers (Joshua Bloch) says that you can work round this by preventing the final value from being considered a constant. For example: public class A { public static final int INT_VALUE = Integer.valueOf(1000).intValue(); public static final String STRING_VALUE = “foo”.toString(); } Of course none of this is relevant if you don’t … Read more

Avoiding getfield opcode

My guess is that the point is to copy the values into local variables once, to avoid having to fetch the field value repeatedly from the heap for each iteration of the loop in the next few lines. Of course, that begs the question as to why the same comment hasn’t been applied on the … Read more

Gradle sourceCompatibility has no effect to subprojects

It seems this behavior is caused by specifying the sourceCompatibility before apply plugin: ‘java’, which happens if you try to set the compatibility option inside allprojects. In my setup, the situation can be solved by replacing: allprojects { sourceCompatibility = 1.6 targetCompatibility = 1.6 } with: allprojects { apply plugin: ‘java’ sourceCompatibility = 1.6 targetCompatibility … Read more

What is the difference between native code, machine code and assembly code?

The terms are indeed a bit confusing, because they are sometimes used inconsistently. Machine code: This is the most well-defined one. It is code that uses the byte-code instructions which your processor (the physical piece of metal that does the actual work) understands and executes directly. All other code must be translated or transformed into … Read more