java之Compiler control

Posted Dreamer who

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java之Compiler control相关的知识,希望对你有一定的参考价值。

Controlling Java Virtual Machine (JVM) compilers might seem like an unnecessary task,
but for many developers, this is an important aspect of testing. This is accomplished with
method-dependent compiler flags.
In this section, we will start with a look at JVM compilation modes and then look at
the compiler that can be controlled using the Java platform.

Compilation modes


The changes in the modern Java platform include granular control of both the C1 and C2
JVM compilers. As you can see in the following illustration, the Java HotSpot JVM has two
JIT compilation modes C1 and C2:

 

The C1 and C2 compilation modes use different compilation techniques and, if used on
the same code base, can produce different sets of machine code.

 

The C1 compilation mode


The C1 compilation mode inside the Java HotSpot VM is typically used for applications
that have the following characteristics:

  • Quick startup
  • Increased optimization
  • Client-side

The C2 compilation mode


The second compilation mode, C2, is used by applications with the following
listed characteristics:

  • Long runtimes
  • Server-side

 

Tiered compilation


Tiered compilation allows us to use both C1 and C2 compilation modes. Starting with Java
8, tiered compilation is the default process. As illustrated here, C1 mode is used at
startup to help provide greater optimization. Then, once the app has sufficiently warmed
up, C2 mode is employed:

 

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:

 

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

 

以上是关于java之Compiler control的主要内容,如果未能解决你的问题,请参考以下文章

java之spring mvc之Controller配置的几种方式

.28-浅析webpack源码之compiler.resolvers

vue编译原理之vue-template-compiler

chromium之compiler_specific

java之spring mvc之数据处理

ScalaScala之Control Structures