Improved JVM compiler control and handling in java 9


Contents of page >


1) Improve the JVM compiler control and handling in java 9 >
Java 9 looks to improve the way JVM compiler is handled. Improve the performance of JVM compiler. With this change JVM compiler could be managed at runtime and also have method dependent compiler flags so that JVM compiler tests could be executed without any need of restarting the whole JVM. It will also add encapsulation (OOP principal) to compiler design in java 9.


2) Compiler directive in java 9 >
Compiler directive is the set of all options required to control the JVM compilers.
Compiler directives contains instructions on how to compile.


2.1) How to load compiler directive file in java 9?
Compiler Directives files can be loaded from CMD (command line).


2.2) What will be format of compiler directives file?
Compiler directives file have human readable file format.
Compiler directives file format will be a subset of JSON with some minor additions in java 9.
So what will be difference between json and Compiler directives file format >
  • It will allow comments >   "//"
  • Extra trailing will be allowed in arrays and the objects > '',"
  • Escape characters are not likely to allowed.
  • Number types Supported > only int and double.


2.3) Compiler directives file can use all the UTF-8 characters as supported by the JVM specification.
Reserved characters for the Compiler directives file >
curly brace open > {
curly brace end > |
square brace open > [
square brace end > ]
quotes > "
colon > :
comma > ,


Java 9 looks to improve the way JVM compiler is handled. Improve the performance of JVM compiler. With this change JVM compiler could be managed at runtime and also have method dependent compiler flags so that JVM compiler tests could be executed without any need of restarting the whole JVM. It will also add encapsulation (OOP principal) to compiler design.


3) Directives patterns in java 9 >
Method patterns that are used in the "match" and "inline" option has the following patterns -
Class.method(signature)


Class includes package names separated by / Class.


Method pattern >
  • can be wildcarded with leading and trailing *,
  • or substituted for *
  • If the signature is left blank it defaults to *


Example of valid method patterns >
  • "java/lang/String,indexOf"
  • "/lang/String,indexOf(I)"
  • "java/lang/String.(I)"
  • "java/lang/String.()"
  • "java/lang/."
  • "."


4) Directives parser in java 9 >
The directives parser is responsible for parsing the directives file and adding the information to an VM internal format in java 9.


5) CompilerBroker in java 9 >
  • The compilerBroker has a directives stack that contains all applied directives.
  • The bottom directive is the default set and can never be removed.
  • When a file is loaded with additional directives they will be added in reverse order, with the first directive in the file ending up on top of the stack.


6) Command line interface for compiler control in java 9 >
A directives file can be added using command line arguments in java 9.
-XX:CompilerDirectivesFile=<file>
The VM will exit with an error message >
  • If file is missing, or
  • if file contents are malformed or corrupt.


7) Diagnostic command interface in java 9 >
Following diagnostic commands that will be used with compiler control >


1) Add additional directives from the file. (As discussed above - When a file is loaded with additional directives they will be added in reverse order, with the first directive in the file ending up on top of the stack)
jcmd <pid> Compiler.add_directives <file>   


2) List all directives on the directives stack from top to bottom.
jcmd <pid> Compiler.list_directives        


3) Clear the directives stack in java 9
jcmd <pid> Compiler.clear_directives     


4) Remove the top element from the directives stack.
jcmd <pid> Compiler.remove_directives


8) CompileCommand and backwards compatibility in java 9 >
.
There are four layers of compiler control >
  1. Compiler Control will have the highest priority (It will override any other command or flag)
  2. CompileCommand - (CompileCommand will be kept for backwards compatibility and the goal is to keep the behaviour as much as possible),
  3. Any command line flag,
  4. Default flag value.
In case Compiler control (1st) and CompileCommand (2nd) are used, then Compiler control will consider that CompileCommand is overriding the default value in java 9.


9) Method patterns in java 9 >
Compiler Control will use the same method pattern format as CompileCommand.
The pattern consists of three parts >
  • package & class name (i.e. Class includes package names separated by / Class.),
  • method name and
  • signature.
Any of the above 3 can be >
  • can be wildcarded with leading and trailing *,
  • or substituted for *
  • If the signature is left out it defaults to *


For Example >
java/example/Test.split
Have following 3 parts >
java/example/Test +
split +
(Ljava/lang/String;)Ljava/lang/String;


Summary >
In this java tutorial we learned about Improved JVM compiler control and handling in java 9.
JVM compiler could be managed at runtime.


Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>

Improve Locking performance in java 9

varHandle (variable handle) in java 9

Improvement in API for controlling and managing the OS processes in java 9


Labels: Core Java Java 9
eEdit
Must read for you :