Questions tagged [jvm-bytecode]

Questions about the JVM .class bytecode format or instruction set.

188 questions
0
votes
2 answers

Is casting a function [X, Y] X => Y to X => () safe as long as I ignore the returned value?

val f = { x :Int => x } val g = f.asInstanceOf[Int, Unit] g(1) //works How brittle is the above code? It works currently, but of course it is not a part of language specification. For this reason, it is of course possible, that one day it will…
Turin
  • 2,208
  • 15
  • 23
0
votes
1 answer

ASM exception: Execution can fall off the end of the code create()V

I'm trying to add a new method public void create(){} to a class using ASM framework, however it throws the exception like below: Exception in thread "main" java.lang.IllegalArgumentException: Execution can fall off the end of the code create()V at…
2BAB
  • 1,215
  • 10
  • 18
0
votes
1 answer

Will jvm evaluate a obvious return value on each execution?

I am sure almost everybody is familiar with the most downvoted question(java tagged) on SO. Copy pasting the snippet for completeness: k = (j = (i = 0) + 2) + 1; return i|= j|= k|= (j+= i) - - (k+++k) - - (i =+j); Above snippet always returns 11 no…
0
votes
1 answer

Java bytecode modification using ASM throws ClassFormatError: Invalid length XXX in LocalVariableTable

I am using ASM (tree and util as well) and have faced a weird exception Exception in thread "main" java.lang.ClassFormatError: Invalid length 65526 in LocalVariableTable in class file I am trying to edit the bytecode of a .class file, to generate…
0
votes
0 answers

C insert newline issue (homework)

I'm writing a Java bytecode program using Jasmin and Yacc, and I want to use fprintf function to write "ldc \"%s\n\"\n" into a .j file, but the resulting file would always lack the newline. For example: fprintf (fp,"ldc \"%s…
李沅翰
  • 1
  • 2
0
votes
0 answers

Java Asm wrap new Instance of specific class init

I want to modify a specific library with ASM for log or modify content. Simply I create an example at above two method for example. I want to convert realMethod to iWantAsLikeThis method with ASM. Usually add like INVOKESTATIC asmTest/Testt.logGet…
utrucceh
  • 1,076
  • 6
  • 11
0
votes
0 answers

How to collect the usage of constant expressions via bytecode analysis?

The class A declares a constant C as follows: public class A { public static final int C = 10; } This constant is used in method M of class B as follows: public class B { public int M() { return A.C; } } In the bytecodes of…
0
votes
1 answer

Compiling/disassembling Java without creating a constant pool?

I'm having trouble understanding the usage of some Java Bytecode Instructions, partially due to lack of examples. Instead, I use javac or Jasmin to compile some regular Java code, and then I use javap -c to inspect the generated bytecode. My project…
thedjdoorn
  • 41
  • 6
0
votes
1 answer

Implementing comparison operators in Bytecode using ASM

I'm working on a personal project of mine creating a simple language which is compiled to Java Bytecode. I'm using the ASM library version 7.3.1 but I've hit a problem with Frames that I can't quite figure out. This is actually two questions rolled…
Oli
  • 1,112
  • 1
  • 10
  • 25
0
votes
1 answer

how to redefine class before bean initialize in spring project

I hava A Class in another jar and i use it in B bean. Now i want to add log for method in A Class. How can i do this in my project without fix the jar. My mind: use ApplicationListener to redefine class before bean init. do something in…
0
votes
1 answer

Unpacking class file (bytes) into ASM ClassNode

Given a class file in the form of an array of bytes, how do you unpack it into an ASM ClassNode with its collection of MethodNodes? The PDF documentation doesn't seem to say – it seems to assume you will only be doing the reverse, creating a new…
rwallace
  • 31,405
  • 40
  • 123
  • 242
0
votes
1 answer

ASM not reporting constant instructions

I'm trying to use the ASM library to read byte code and translate it into a different format. Starting off with a simple test class containing this method: public static double square(double a) { return a * a; } Which compiles to this byte…
rwallace
  • 31,405
  • 40
  • 123
  • 242
0
votes
1 answer

Does the instruction istore start at index 1 in the main method?

Given the instruction istore_ and its documentation: n must be an index into the local variable array of the current frame (§2.6). It does not specify what index it starts at. I assume 0. And for a given istore operation it should increment by…
gel
  • 281
  • 3
  • 19
0
votes
0 answers

How to find the current values of the local variables of some general method?

I am trying to write a utility method that would capture a snapshot of the current values of the local variables (if I understand it correctly, from a bytecode point of view, these include also the method parameters) of the method within which it is…
rapt
  • 11,810
  • 35
  • 103
  • 145
0
votes
1 answer

Where is JVM PC stored during a call?

I am currently reading the last specification of the JVM. It is clear that each thread has its own call stack and its own program counter that keeps track of the (next) instruction to execute. My question is maybe dump, but from the description, I…
Briomkez
  • 567
  • 3
  • 17