Compiler control in Java 11

Java comes with the promise of the ability to have finite control over JVM compilers and to make changes at runtime. These additional abilities do not degrade performance. This permits greater fidelity of testing and testing optimization as we can run small compiler tests without having to relaunch the entire JVM.

To control compiler operations, we need to create a directives file. These files contain compiler directives that consist of a set of options with values. Directive files essentially use a subset of JSON:

Compiler directive structure

The JavaScript Object Notation (JSON) format is used for data-interchange. The directive files have the following formatting differences from JSON:

  • int and doubles are the only supported number formats
  • The double forward slash (//) can be used for comment lines
  • Trailing commas (,) can be used in arrays and objects
  • Escape characters are not supported
  • Option names are formatted as strings and do not have to be quoted
You can learn more about JSON at http://www.json.org.

We can add our directive file using the following syntax at the command line:

-XX:CompilerDirectivesFile=<file>

Here is a shell example of a directives file:

[ // Open square bracket marks the start of the directives file

{ // Open curly brace marks the start of a directive block
// A directives block that applies specifically to the C1 mode
c1: {
// directives go here
},

// A directives block that applies specifically to the C2 mode
c2: {
// directives go here
},

// Here we can put a directives that do not apply to
// a specific compiler mode
},

{ // can have multiple directive blocks

c1: {
// directives go here
}

c2: {
// directives go here
}
}
] // Close square bracket marks the start of the directives file
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset