Bytecode knowledge network architecture

What’s the use of bytecode? Knowing bytecodes will take you to the next level.

As a coder, you can write Java code, but you don’t know why.

Your excellency, times have changed. Gone are the days when you could go to work with a computer.

If you can’t roll someone else, you’ll be rolled.

The knowledge system

We all know that Java emerged around a vision:

It was difficult for programmers to write the same logic several times, because the underlying instruction set on different OS in those days might be different. We in IT can solve problems in a layered way, one layer is not enough then add another layer, that’s how TCP was created.

Java field, also abstract out a layer, down to shield OS, up can be unified, real implementation, write one time, run everywhere.

The thing that is abstracted out of the Java domain is the JVM, and the thing that interconnects with the JVM itself is what we call bytecode.

Java code, on the other hand, is a higher layer of abstraction that shields the language itself. Things like Scala, Groove, and Kotlin can all run on the JVM, which is the benefit of shielding languages.

So let’s take a look at the Java process from writing to running.

Java code -> the JDK’s own instruction javac is compiled to generate a JVM recognized. Class file -> Run the Java instruction to run the code just written, and then it’s JVM territory.

As you can see from the above figure, understanding bytecode itself has many benefits. You know what goes on behind the scenes when you write Java, and with that foundation, you can imagine how each line of code will behave. At the same time, the mental supplement will make up for the previous knowledge of the JVM itself.

knowledge

  1. Class file structure
  2. Java code from a bytecode perspective
    1. Basic data types and operator operations
    2. Process control
    3. Object initialization
    4. Method calls and polymorphisms
    5. Exception catching and handling
    6. Concurrent keyword
  3. Bytecode rewriting framework
  4. Agent Parasitic plug-in

Since we’re going to dive into bytecodes, it’s natural to know the structure of bytecodes, and you’ll learn a lot of ideas on class file structure design

  • How to minimize large amounts of information
  • How do you create a stable, extensible file format
  • Know how to make bytecode files that are as backward compatible as possible

Then we can compare ourselves to the Java language and see what’s going on behind the scenes of our regular Java code, learning enough to write code with divine blessing.

Bytecode, to some extent, opens the door for developers to dynamically modify bytecode at run time, performing one hack after another. That’s where Skywalking comes in. It acts as a proxy on top of the JVM. Behind it is the Agent plug-in, which runs with the JVM and is therefore called a plug-in. Plugins can be attached using Either Java runtime instructions or socket connections, which is arthas’s way of connecting. The Instrument package in the JDK does just that.

So if you want to play with this whole thing, you have to know the bytecode instructions themselves, and rewriting bytecode can be done with the help of the framework, because bytecode is complicated. The API of the bytecode rewriting framework should be as familiar as possible. There are many bytecode rewriting frameworks, just pick one you are familiar with.

Logically, if you want a closed loop, you need to know how the class is generated and how the class file is run in the JVM.

The former requires knowledge of how compilation works, the more detailed javAC compilation works, and the latter is more complex, requiring extensive knowledge of the JVM domain to produce a closed loop.

It’s the liver. Don’t be afraid. Even on your knees.