Whats the difference between a normal instruction and a fast instruction in java (e.g. aload and fast_aload)

Neintanke :

I printed out the executed bytecodes of a simple java program and noticed that some java instructions are fast_xxxx instead of the normal instruction.

I could not find anything about that in the JVM Specification. So what exactly is the difference between these instructions and when/why does the interpreter choose to use these?

Edit: The bytecodes were printed with the -XX:TraceBytecodes option.

Mikhail Kholodkov :

So what exactly is the difference between these instructions?

In short: fast_ variants are optimized architecture dependent instruction replacements

Where do these optimizations come from?

The JVM module interpreter. It can work in non-patching and patching modes. Some related JVM options:

RewriteBytecodes - Allow rewriting of bytecodes

RewriteFrequentPairs - Rewrite frequently used bytecode pairs into a single bytecode

...

Implementation - https://hg.openjdk.java.net/jdk/jdk11/file/tip/src/hotspot/share/interpreter/bytecodeInterpreter.cpp

And

http://hg.openjdk.java.net/jdk/jdk11/file/tip/src/hotspot/share/interpreter/bytecodes.cpp - contains the definitions of a number of the fast bytecodes (see Bytecodes::initialize()) where a set of fast bytecodes is defined. Also, the fast bytecodes can be defined in a platform dependent area of code. The rewritten bytecodes are architecture dependant. Well, at least, some of them are, and some of them are not.

When/why does the interpreter choose to use these?

JVM has the capability to rewrite the bytecode stream, for example to combine common instruction pairs. At least most, if not all, of the bytecode transformations to the fast_ versions are done simply for performance and can be disabled. Doing so impacts interpreter performance.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=139831&siteId=1