Questions tagged [bytecode]

"bytecode" is a blanket term for opcodes that are consumed by a virtual machine. For example, the JVM runs bytecode stored in .class files and the CPython interpreter runs bytecode stored in .pyc files.

Bytecode, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normally numeric addresses) which encode the result of parsing and semantic analysis of things like type, scope, and nesting depths of program objects. They therefore allow much better performance than direct interpretation of source code.

The name bytecode stems from instruction sets which have one-byte opcodes followed by optional parameters. Intermediate representations such as bytecode may be output by programming language implementations to ease interpretation, or it may be used to reduce hardware and operating system dependence by allowing the same code to run on different platforms. Bytecode may often be either directly executed on a virtual machine (i.e. interpreter), or it may be further compiled into machine code for better performance.

Since bytecode instructions are processed by software, they may be arbitrarily complex, but are nonetheless often akin to traditional hardware instructions; virtual stack machines are the most common, but virtual register machines have also been built. Different parts may often be stored in separate files, similar to object modules, but dynamically loaded during execution.

Source: Wikipedia (Bytecode)

Understanding bytecode makes you a better programmer https://www.ibm.com/developerworks/ibm/library/it-haggar_bytecode/

2276 questions
1
vote
1 answer

Running code in Java Agents after the execution? post main?

I'm working with Java Agent (creating a profiler) using code instrumentation (using Javassist for Instrumentation). I need to run few functions in my Java Agent profiler after the complete execution of java program. Something after the main…
ammar26
  • 1,584
  • 4
  • 21
  • 41
1
vote
2 answers

Java Bytecode Manipulation - How to inject in middle of method?

I have seen many frameworks around that let you inject bytecode into Java classes at runtime. But in all of the examples and documentation, they just show how to inject BEFORE and AFTER methods. But I need to inject somewhere in the MIDDLE of a…
AppleDash
  • 1,544
  • 2
  • 13
  • 27
1
vote
1 answer

What is the relation between an interpreter and CPU?

I have read that the interpreter (VM) is a software that executes code. I have also read that the CPU executes the instructions. What is the difference between the two execution? The VM does not convert the byte code into machine code. What does it…
codingsplash
  • 4,785
  • 12
  • 51
  • 90
1
vote
1 answer

JVM bytecode line number

We are trying to analyze Java code with only bytecode. Is there a way to either let JVM spit out the addresses of bytecode it is executing or intercept the addresses of the bytecode issued to JVM at runtime ? According to the crash stack, it seems…
Farn Wang
  • 143
  • 15
1
vote
1 answer

Method intercepted twice even though it was called once

In the following code snippet I'm calling the method doStuff once on an instance of Subclass. However it is intercepted twice. Note that doStuff was defined in the parent class SuperClass. If doStuff was defined in SubClass the interception logic…
user3408654
  • 301
  • 1
  • 13
1
vote
1 answer

Ruby bytecode debugger

I have been able to extract the YARV bytecode list of instructions from a "compiled" ruby file using RubyVM::InstructionSequence#disassemble. Now I would like to debug the code instruction by instruction. Is there any debugger that let me do…
user1618465
  • 1,813
  • 2
  • 32
  • 58
1
vote
1 answer

How to load different primitive datas to the operand stack

JVM has two instructions: bipush (operand value should be between Byte.MIN_VALUE and Byte.MAX_VALUE.) and sipush (operand value should be between Short.MIN_VALUE and Short.MAX_VALUE). Correspondingly, the MethodVisitor in the ASM provide the API to…
shijie xu
  • 1,975
  • 21
  • 52
1
vote
2 answers

Access byte code generated by ruby for sample program

Is there any way to access the byte code created by the Ruby program for the following sample piece of code? x=1 x.to_s puts x
1
vote
1 answer

Java: What classes can not be transformed by an agent or by MBean?

I wonder which classes I can not intercept and manipulate by using byte code transformation and java agents. Q1: I know not all classes can be redefined (altered, manipulated) on load as well as later on. These classes include methods that are…
Martin Kersten
  • 5,127
  • 8
  • 46
  • 77
1
vote
2 answers

How do I simulate JIT optimizations to view the optimized byte code?

Is there a way (in Eclipse, preferably) to simulate JIT optimizations of my code? I can use Bytecode Visualizer to see the non-optimized version, but what I also want to see is how the code changes over time with the JIT optimizations. I want to…
HesNotTheStig
  • 549
  • 1
  • 4
  • 9
1
vote
1 answer

Annotations to transform DTO to Entity using Byte Buddy

I have a simple entity User. public class User { String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } And his corresponding DTO public class UsuarioDTO { String…
gabrielgiussi
  • 9,245
  • 7
  • 41
  • 71
1
vote
1 answer

When local variable stack gets created?

I am learning internals of jvm and i read this article. While reading i got one doubt i.e When local variable stack get created ? If local variable stack created at run time will this, super keywords point real objects Or if local variable stack is…
Ramesh Papaganti
  • 7,311
  • 3
  • 31
  • 36
1
vote
4 answers

Is it more efficient to access array elements through the array than to get them through a function?

I'm thinking about making an object that consists of a large grid, stored in a two dimensional array, and functions that work on that grid. If I want to iterate through the elements in this array outside of the object, the most readable and…
Bibendum
  • 502
  • 4
  • 7
  • 18
1
vote
2 answers

How to detect java local variables by an interface type and then find methods called on them?

I have some (maybe) strange requirements - I wanted to detect definitions of local (method) variables of a given interface name. When finding such a variable I would like to detect which methods (set/get*) will be called on this variable. I tried…
PowerStat
  • 3,757
  • 8
  • 32
  • 57
1
vote
2 answers

How to load a constant complex object to a stack using LDCInsnNode in ASM

I want to use ASM library to create a bytecode method that is capable of returning a constant value at runtime. One of class in the ASM I can use is the LdcInsnNode. So my sample code is: class Myclass{ final const Object value; @Override …
shijie xu
  • 1,975
  • 21
  • 52