官术网_书友最值得收藏!

Usage of CDS

You can manually control usage of CDS by switching it on, switching it off, or putting it on automode. These are the command-line options to do so:

  • java -Xshare:off: Disables CDS
  • java -Xshare:on: Enables CDS
  • java -Xshare:auto: The default mode (it enables CDS whenever possible)

Let's quickly define a class as follows:

class ConquerWorld { 
    public static void main(String args[]) { 
        System.out.println("Go and conquer the world"); 
    } 
} 

Let's execute the preceding class (ConquerWorld) using the shared archive file, classes.jsa. To view the system class loading from the shared archive, you can use a log file with class execution, as follows:

    java -Xlog:class+load:file=myCDSlog.log ConquerWorld  

The preceding command outputs the following:

    Go and conquer the world  

Let's examine the contents of the myCDSlog.log file (I've highlighted text to draw your attention to specific lines; the highlighted text isn't included in the log file):

The classes.jsa file is also referred to as the shared objects file. JVM loads approximately 500 classes or interfaces from classes.jsa to set up the execution environment. It loads the bytecodes of the ConquerWorld class from the relevant location on the system.

If you scrutinize the  myCDSlog.log file, you'll notice that a few of the classes are not loaded from the shared objects file. This is because they couldn't be archived; this can happen in certain cases.

Let's see what happens if you execute the same class (ConquerWorld) by stating that you don't want to use the shared objects file. To do so, you can use the -Xshare:off command, as follows:

    java -Xshare:off -Xlog:class+load:file=myCDSshareoff.log     
ConquerWorld

The preceding code will output the same result as it did previously. Let's examine the contents of the myCDSshareoff.log file:

As you can see, since the preceding execution no longer uses the shared objects file (which was turned off using the Xshare:off option), the system or core API classes are loaded at runtime from their respective modules. As highlighted at the left bottom of the screenshot, you can also see that this execution takes a longer amount of time, that is, approximately 0.110 seconds. This time exceeds the execution time of 0.083 seconds for similar execution, which used the shared archive (shown in previous screenshot).

With the basic information on how CDS can lower execution time for your code, let's get started with AppCDS.

主站蜘蛛池模板: 长白| 新绛县| 高青县| 厦门市| 临清市| 仪征市| 沈阳市| 安阳县| 醴陵市| 观塘区| 南木林县| 社旗县| 娄烦县| 南投县| 通辽市| 综艺| 吉林省| 江门市| 广宁县| 济宁市| 陇川县| 循化| 荔波县| 大宁县| 定兴县| 驻马店市| 丰镇市| 英德市| 伊金霍洛旗| 金华市| 仪征市| 锡林浩特市| 景东| 扬中市| 石阡县| 吉木乃县| 明水县| 肇东市| 民丰县| 阳山县| 若尔盖县|