jvm Series Notes - command line parameters

java command line

Java program execution

Two ways:

  • One is to use -cpthe parameter, and a lot of incoming packets jar, then passing the main class, and finally passing the program parameters. E.g:
    • java -Dkey1=val1 -Dkey2=val2 -cp a.jar:b.jar:c.jar aaa.bbb.ccc.Main arg1 arg2 arg3
    • The above-described manner, -Dthe parameter is defined in the system properties , in java by System.getProperty(key1)way of reading arg1 arg2 arg3the definition of the process parameters, i.e. the final mainfunction of argsthe array parameter.
  • The second is to use a -jarparameter, then passed a jar package, followed by the program parameters. E.g:
    • java -Dkey1=val1 -Dkey2=val2 -jar xxx.jar arg1 arg2 arg3
    • This can only use a jar package, and the package needs manifest.MF jar file in the directory META_INF defined in Main-Class, it will automatically go to start the main class

By the way, System.getEnv()get the environmental variable is the environment variable process in the usual sense (jvm essence is a process), System.getProperty(key1)to obtain a system property, this is the definition of a java own parameters, arg1 arg2is the program parameters, this corresponds to the main function of the received parameters.

Virtual machine parameters

Configuration mode of operation, the size of the stack space, stack frame

-client -server

  • It indicates the operating mode of the virtual machine, server mode slow start, but the performance is higher than the overall running client, optimized for more (so long warm-up time)

-Xss1024k

  • Represents the thread's stack space is 1024k, thread stack depth is actually no limit (there may be other restrictions I do not know), was the result of StackOverflow exception, because of the size of the stack space reaches the limit.
  • Each element is thread stack stack frame, the size of the stack frame is not fixed (one for each method call stack frame). So if the big stack frame, then the stack depth will be small, small stack frame, stack depth will be large (because the stack space stack frame size = * deep stack).
  • Stack frame can be understood as a section of memory, the stack itself is not stack frame-like structure, it may be made of a random access read and write in the stack frame.
  • Stack frame including at least table of local variables , an operand stack , the frame data area .

The structure of the stack frame

Local variable table

Very simple, our method parameters, local variables declared inside the method, there is a local variable table. Local variables, there will be a bunch of slots, a slot you can put a data (a byte, a char, a short ... and so on, as well as a reference). Virtual machine data list of local variables used by the indexing slot (slot 0 reference example, may correspond to a digital 3, a reference slot 2, may correspond to an object reference)

Operand stack

Operand stack is a stack frame of the stack (that is, in the stack frame of several pieces of different regions, wherein an area used as a stack, that is the operand stack). It is mainly used to hold intermediate results of calculations, as well as the temporary storage variable calculation process (mode because some instructions operate the stack and the stack is calculated).

Frame data

In addition to the above stack frame of data, some data needed to support the constant pool analysis, the method returns, and exception handling. For instance, we returned value is stored where, exception handling, storage table where these need to be placed frame data area, jvm can achieve some level of data stored in the area here.

Allocated on the stack

It's optimized technology, the basic idea is that the object can not be accessed by other threads to be broken allocated on the stack. For example, we created a temporary object in the method, the receiver is also a local object reference variables, objects nor to other methods. Then the object would not have happened escape, it may be allocated in a stack manner. (Stack space is small, so small objects can only be assigned) benefit is the stack frame is recovered when the object will be directly recycled.

Yuan spatial parameters

-XX:MaxMetaspaceSize=10m

  • Jvm expressed using meta-space size is 10M
  • Element space information stored in the class, such as the fields of the class, method, constant pool, etc.
  • Memory element space belongs outside the heap memory. If you do not specify a size, java8 default is not set dollar limit, it will grow up to run out of system memory when needed.
  • Greater dimensional space, the system can be loaded more classes (since the information classes are loaded here, so that require dynamic proxy framework or program there will be some space consumption membered)

GC parameters

-XX:+PrintGC

  • GC print information, when faced with GC, GC the JVM prints the information, as in FIG.
  • Once you have GC information, we are more easily monitored during use and effect of the GC

-XX:+PrintGCDetails

  • Print detailed information GC, GC information more detailed and rich. It will be before the JVM exits, print details of the heap.
  • PSYoungGen represents the young generation of eden + from area
  • ParOldGen represents years old
  • space 65536K, 2% used [0x000000076ab00000,0x000000076acb4e98,0x000000076eb00000) Three digits indicate the lower bound of memory, the current upper bound, upper bound.

-XX:+PrintHeapAtGC

  • Each time after the GC, all details heap of print, this is even more detailed than the above detail.

-XX:+PrintGCTimeStamps

  • GC logs per print time, but also output time information (time after the system starts).

-XX:+PrintGCApplicationConcurrentTime

  • Print execution time of the application (arrival time security point safepoint's), is generally used in conjunction with the following parameters

-XX:+PrintGCApplicationStoppedTime

  • Print application because GC pause time (stw mechanism)

-XX: + PrintReferenceGC

  • Print references related to GC. This may be tracked within the system referenced soft, weak reference, and references Finallize virtual queue.

-Xloggc:log/gc.log

  • By default GC log is output directly in the console (standard output), this parameter can be output to where we specified here is to say gc.log files in the log directory of the current directory.

Class information parameters

-verbose:class 或 -XX:+TraceClassLoading 与 -XX:+TraceClassUnloading

  • These two types of parameters are equivalent, are tracking class loading and unloading
  • -verbose: class loading and unloading track class
  • -XX: + TraceClassLoading trace class loading
  • -XX: + TraceClassUnloading tracking class unloading

-XX:+PrintClassHistogram

  • It allows printing and viewing information distribution system in class
  • When you turn on this parameter, the java console is pressed Ctrl + Break, the console will display the current class information histogram. Below shows the current largest space class, instance number, and other space

System parameters themselves relevant parameters

-XX:+PrintFlagsFinal

  • Print all system parameters

-XX:+PrintCommandLineFlags

  • Print transmitted to the implicit and explicit parameters, parameters of the virtual machine implicit command line may not be given, it may be self-set when the virtual machine is started.

Heap space parameters

-Xms10m -Xmx20m

  • The minimum heap memory 10m
  • The maximum heap memory 20m
  • Many production projects are set directly into the same big, all set to direct the maximum memory. Such a start is the maximum memory usage, reduce the number of GC improve performance and prevent memory copy (when expanded memory may occur)

-Xmn3m

  • Set the size of the new generation is 3m
  • Typically set to 1/3 the size of the entire heap 1/4

-XX:SurvivorRatio=2

  • He represents the new generation, eden / from (and eden / to) ratio is 2
  • For example, the new generation of memory 40m, then the eden zone is 20m, from and to all 10m

-XX:NewRatio=3

  • The ratio represents years old / new generation of 3
  • For example, a total of heap memory is 40m, so the new generation of 10m, 30m years old

Heap overflow processing parameters

-XX:+HeapDumpOnOutOfMemoryError

  • When memory overflow, the whole heap of export information

-XX:HeapDumpPath=d:/a.dump

  • When the memory overflows, heap of information is exported to this file. Using the above parameters with
  • After you export the dump file, you can use the tool to analyze MAT

-XX:OnOutOfMemoryError=d:/tools/printstack.bat

  • Memory overflow when the implementation of the script
  • Generally used alarm, notification, or Core Dump memory Thread Dump file for analysis

Direct memory parameters

-XX:MaxDirectMemorySize=100m

  • It is the largest direct memory 100m
  • The default value is the maximum heap memory with the same

Guess you like

Origin juejin.im/post/5d898610518825090f4199e1