Java Optimizations and the JMM
playingwithpointers.com69 pointsby thedigitalengel5 comments
int _a = 50;
int result = min(num, _a);
you end up expanding to "int _a = _a;" which creates a new int _a, and assigns it to itself. data_t *global;
int main() {
atexit(callback);
atexit(set_global_to_x);
atexit(callback);
atexit(set_global_to_y);
}
Since functions are called in reverse order of their installation using atexit, you end up with two calls to callback; one with global set to y and one with global set to x. int array = { ... } // holds the source code,
// except its own representation
int array_index; // The index in the source code
// (where the actual integers in
// array interpreted as source appear)
for i = 0 to array_index:
print (array[i] as an ASCII character)
for i = 0 to array_length:
print (array[i] as integer ++ ", ")
for i = array_index + 1 to array_length:
print (array[i] as an ASCII character)
The core idea is that you can interpret `array` in two ways, as an array of integers or an array of ascii characters representing the program source. The only difficult part is adjusting array_index. With a little effort, this can be scaled to a chain of languages.
The right way to look at Java's bytecode stream is opcodes for a register machine with _implicit_ input and output registers. Mapping it to a compiler IR would not be easy in the general case if that weren't true.