Thursday, 29 December 2016

Way to find final Xtra arguments used by JVM or Java running process

$java -XX:+PrintCommandLineFlags -XX:+UseG1GC -XX:InitiatingHeapOccupancyPercent=45 -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15 -XX:+UseStringDeduplication -Xloggc:/home/jboss/Logs/gc/gc.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintAdaptiveSizePolicy -XX:+PrintTenuringDistribution -Xms2048m -Xmx2048m -Djava.net.preferIPv4Stack=true -verbose:gc -version

-XX:InitialHeapSize=2147483648 -XX:InitiatingHeapOccupancyPercent=45 -XX:+ManagementServer -XX:MaxHeapSize=2147483648 -XX:MaxTenuringThreshold=15 -XX:+PrintAdaptiveSizePolicy -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:+UseStringDeduplication

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)




If we observe the  verbose:gc option is not shown as it is ignored by JVM.

Wednesday, 7 December 2016

Oracle JVM Garbage Collectors Available From JDK 1.7.0_04 And After



Ref: http://www.fasterj.com/articles/oraclecollectors1.shtml

With G1 finally being officially supported - i.e. no longer an experimental garbage collector - in the 1.7.0_04 (Java 7 update 4) release, it's worth taking stock of what we now have available in terms of garbage collectors in the Sun JVM. All the following details are relevant specifically to the Sun JVMs from 1.7.0_04 on.
There are now seven primary garbage collection algorithms, one of which (PS Scavenge) has two modes that are sufficiently different that I would call them two different algorithms (that is, with and without adaptive GC), and another (the concurrent collector) which has a huge number of options that makes it actually at least half a dozen algorithms in one! It's useful to list the garbage collectors so that's what I'll do here.
First I'll characterise the actual different primary garbage collectors. There are seven (I'm counting the G1 collector as one):

Young generation collectors


Copy (enabled with -XX:+UseSerialGC) -
the serial copy collector, uses one thread to copy surviving objects from Eden to Survivor spaces and between Survivor spaces until it decides they've been there long enough, at which point it copies them into the old generation.
PS Scavenge (enabled with -XX:+UseParallelGC) -
the parallel scavenge collector, like the Copy collector, but uses multiple threads in parallel and has some knowledge of how the old generation is collected (essentially written to work with the serial and PS old gen collectors).
ParNew (enabled with -XX:+UseParNewGC) -
the parallel copy collector, like the Copy collector, but uses multiple threads in parallel and has an internal 'callback' that allows an old generation collector to operate on the objects it collects (really written to work with the concurrent collector).
G1 Young Generation (enabled with -XX:+UseG1GC) -
the garbage first collector, uses the 'Garbage First' algorithm which splits up the heap into lots of smaller spaces, but these are still separated into Eden and Survivor spaces in the young generation for G1.

Old generation collectors


MarkSweepCompact (enabled with -XX:+UseSerialGC) -
the serial mark-sweep collector, the daddy of them all, uses a serial (one thread) full mark-sweep garbage collection algorithm, with optional compaction.
PS MarkSweep (enabled with -XX:+UseParallelOldGC) -
the parallel scavenge mark-sweep collector, parallelised version (i.e. uses multiple threads) of the MarkSweepCompact.
ConcurrentMarkSweep (enabled with -XX:+UseConcMarkSweepGC) -
the concurrent collector, a garbage collection algorithm that attempts to do most of the garbage collection work in the background without stopping application threads while it works (there are still phases where it has to stop application threads, but these phases are attempted to be kept to a minimum). Note if the concurrent collector fails to keep up with the garbage, it fails over to the serial MarkSweepCompact collector for (just) the next GC.
G1 Mixed Generation (enabled with -XX:+UseG1GC) -
the garbage first collector, uses the 'Garbage First' algorithm which splits up the heap into lots of smaller spaces.

All of the garbage collection algorithms except ConcurrentMarkSweep are stop-the-world, i.e. they stop all application threads while they operate - the stop is known as 'pause' time. The ConcurrentMarkSweep tries to do most of it's work in the background and minimize the pause time, but it also has a stop-the-world phase and can fail into the MarkSweepCompact which is fully stop-the-world. (The G1 collector has a concurrent phase but is currently mostly stop-the-world).

Combinations of Garbage Collectors

That's the set of garbage collectors available, but they operate in two different heap spaces and it's the combination that is what we actually end up with for a particular JVM setting, so I'll also list the combinations that are possible. It doesn't explode into a dozen combinations because not all of these collectors work with each other. G1 is effectively an antisocial collector that doesn't like working with anyone else; the serial collectors are the "last man picked" collectors; the 'PS' collectors like to work with each other; and ParNew and Concurrent like to work together. From Java 9 that's pretty much it (with the addition of being able to turn off adaptive sizing policy) Before that it wasn't quite as simple as that, so here is the list of what I consider are the main options in terms of garbage collection algorithm options. As an aside for those who like a bit of trivia, we have actually lost one garbage collection algorithm over time, the "train" (incremental) garbage collector which was available in various JVMs as -Xincgc and -XX:+UseTrainGC - these flags are no longer useful, the former flag is just silently converted into using ParNew and Concurrent, while the latter flag will cause a startup error in this JVM, and from Java 9 we also lose the incremental algorithm in the concurrent collector.
The full list of possible GC algorithm combinations that can work are:
Command Options*Resulting Collector Combination
-XX:+UseSerialGCyoung Copy and old MarkSweepCompact
-XX:+UseG1GCyoung G1 Young and old G1 Mixed
-XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicyyoung PS Scavenge old PS MarkSweep with adaptive sizing
-XX:+UseParallelGC -XX:+UseParallelOldGC -XX:-UseAdaptiveSizePolicyyoung PS Scavenge old PS MarkSweep, no adaptive sizing
-XX:+UseParNewGC (deprecated in Java 8 and removed in Java 9 - for ParNew see the line below which is NOT deprecated)young ParNew old MarkSweepCompact
-XX:+UseConcMarkSweepGC -XX:+UseParNewGCyoung ParNew old ConcurrentMarkSweep**
-XX:+UseConcMarkSweepGC -XX:-UseParNewGC (deprecated in Java 8 and removed in Java 9)young Copy old ConcurrentMarkSweep**
*All the combinations listed here will fail to let the JVM start if you add another GC algorithm not listed, with the exception of -XX:+UseParNewGC which is only combinable with -XX:+UseConcMarkSweepGC
**there are many many options for use with -XX:+UseConcMarkSweepGC which change the algorithm, e.g.
  • -XX:+/-CMSIncrementalMode (deprecated in Java 8 and removed in Java 9) - uses or disables an incremental concurrent GC algorithm
  • -XX:+/-CMSConcurrentMTEnabled - uses or disables parallel (multiple threads) concurrent GC algorithm
  • -XX:+/-UseCMSCompactAtFullCollection - uses or disables a compaction when a full GC occurs

Other options equivalent to one of the above:
Command Options Used On Their OwnEquivalent To Entry In Table Above
-XX:+UseParallelGC-XX:+UseParallelGC -XX:+UseParallelOldGC
-XX:+UseParallelOldGC-XX:+UseParallelGC -XX:+UseParallelOldGC
-Xincgc (deprecated in Java 8 and removed in Java 9)-XX:+UseParNewGC -XX:+UseConcMarkSweepGC
-XX:+UseConcMarkSweepGC-XX:+UseParNewGC -XX:+UseConcMarkSweepGC
no option on most Windows-XX:+UseG1GC from Java 9, or before that -XX:+UseSerialGC (see also this page)
no option on most Unix-XX:+UseG1GC from Java 9, or before that -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy (see also this page)
-XX:+AggressiveHeap-XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy with a bunch of other options related to sizing memory and threads and how they interact with the OS

Friday, 18 March 2016

Set up Maven Project to work for Eclipse

Now a day it is very easy to create java projects with the help of using maven archetype artifact. 

The next problem is how t ointegrate this maven project in eclipse, so that we do not have to tell eclipse about dependencies again.

I generally use eclipse plugin of maven. Here is the command..

mvn eclipse:eclipse -Dwtpversion=2.0 -DdownloadSources=true -DdownloadJavadocs=true  -DoutputDirectory=bin -DeclipseProjectDir=C:\EclipseWorkspace

If you have working eclipse workspace and you copied it to some other machine, if you want to download all maven dependencies once... You can use below command

mvn eclipse:resolve-workspace-dependencies

One can get usage details of each goal by using below command..

mvn eclipse:help -Ddetail=true -Dgoal=eclipse

Here is sample output :
eclipse:eclipse  Generates the following eclipse configuration files:  - .project and .classpath files  - .setting/org.eclipse.jdt.core.prefs with project specific compiler settings  - various configuration files for WTP (Web Tools Project), if the parameter    wtpversion is set to a valid version (WTP configuration is not generated by    default)  If this goal is run on a multiproject root, dependencies between modules will  be configured as direct project dependencies in Eclipse (unless  useProjectReferences is set to false).
  Available parameters:
    addGroupIdToProjectName (Default: false)      If set to true, the groupId of the artifact is appended to the name of the      generated Eclipse project. See projectNameTemplate for other options.      User property: eclipse.addGroupIdToProjectName
    additionalBuildcommands      List of eclipse build commands to be added to the default ones. Old style:      <additionalBuildcommands>
      <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>      </additionalBuildcommands>      New style:      <additionalBuildcommands>       <buildCommand>       <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>       <triggers>auto,full,incremental,</triggers>       <arguments>
      <LaunchConfigHandle>&lt;project&gt;./externalToolBuilders/MavenBuilder.launch</LaunchConfighandle>       </arguments>       </buildCommand>      </additionalBuildcommands>      Note the difference between buildcommand and buildCommand. You can mix and      match old and new-style configuration entries.
    additionalConfig      Allow to configure additional generic configuration files for eclipse that      will be written out to disk when running eclipse:eclipse. FOr each file      you can specify the name and the text content.      <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-eclipse-plugin</artifactId>       <configuration>       <additionalConfig>       <file>       <name>.checkstyle</name>       <content>       <![CDATA[<fileset-config file-format-version='1.2.0'      simple-config='true'>       <fileset name='all' enabled='true' check-config-name='acme corporate      style' local='false'>       <file-match-pattern match-pattern='.' include-pattern='true'/>       </fileset>       <filter name='NonSrcDirs' enabled='true'/>       </fileset-config>]]>       </content>       </file>       </additionalConfig>       </configuration>      </plugin>      Instead of the content you can also define (from version 2.5) an url to      download the file :      <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-eclipse-plugin</artifactId>       <configuration>       <additionalConfig>       <file>       <name>.checkstyle</name>       <url>http://some.place.org/path/to/file</url>       </file>       </additionalConfig>       </configuration>      or a location :      <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-eclipse-plugin</artifactId>       <configuration>       <additionalConfig>       <file>       <name>.checkstyle</name>       <location>/checkstyle-config.xml</location>       </file>       </additionalConfig>       </configuration>       <dependencies>       <!-- The file defined in the location is stored in this dependency -->       <dependency>       <groupId>eclipsetest</groupId>       <artifactId>checkstyle-config</artifactId>       <version>1.0</version>       </dependency>       </dependencies>      </plugin>
    additionalProjectFacets      List of eclipse project facets to be added to the default ones.      <additionalProjectFacets>       <jst.jsf>1.1<jst.jsf/>      </additionalProjectFacets>
    additionalProjectnatures      List of eclipse project natures to be added to the default ones.      <additionalProjectnatures>
      <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>      </additionalProjectnatures>
    addVersionToProjectName (Default: false)      If set to true, the version number of the artifact is appended to the name      of the generated Eclipse project. See projectNameTemplate for other      options.      User property: eclipse.addVersionToProjectName
    ajdtVersion (Default: none)      The version of AJDT for which configuration files will be generated. The      default value is '1.5', supported versions are 'none' (AJDT support      disabled), '1.4', and '1.5'.      User property: eclipse.ajdtVersion
    buildcommands      List of eclipse build commands. By default the      org.eclipse.jdt.core.javabuilder builder plus the needed WTP builders are      added. If you specify any configuration for this parameter, only those      buildcommands specified will be used; the defaults won't be added. Use the      additionalBuildCommands parameter for that. Configuration example: Old      style:      <buildcommands>
      <buildcommand>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder</buildcommand>       <buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
      <buildcommand>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver</buildcommand>      </buildcommands>      For new style, see additionalBuildCommands.
    buildOutputDirectory (Default: ${project.build.outputDirectory})      The default output directory      Required: Yes      User property: outputDirectory
    classpathContainers      List of container classpath entries. By default the      org.eclipse.jdt.launching.JRE_CONTAINER classpath container is added.      Configuration example:      <classpathContainers>
      <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
      <classpathContainer>org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache      Tomcat v5.5</classpathContainer>
      <classpathContainer>org.eclipse.jst.j2ee.internal.web.container/artifact</classpathContainer>      </classpathContainers>
    classpathContainersLast (Default: false)      Put classpath container entries last in eclipse classpath configuration.      Note that this behaviour, although useful in situations were you want to      override resources found in classpath containers, will made JRE classes      loaded after 3rd party jars, so enabling it is not suggested.      User property: eclipse.classpathContainersLast
    downloadJavadocs      Enables/disables the downloading of javadoc attachments. Defaults to      false. When this flag is true remote repositories are checked for      javadocs: in order to avoid repeated check for unavailable javadoc      archives, a status cache is mantained. With versions 2.6+ of the plugin to      reset this cache run mvn eclipse:remove-cache, or use the forceRecheck      option with versions. With older versions delete the file      mvn-eclipse-cache.properties in the target directory.      User property: downloadJavadocs
    downloadSources      Enables/disables the downloading of source attachments. Defaults to false.      When this flag is true remote repositories are checked for sources: in      order to avoid repeated check for unavailable source archives, a status      cache is mantained. With versions 2.6+ of the plugin to reset this cache      run mvn eclipse:remove-cache, or use the forceRecheck option with      versions. With older versions delete the file mvn-eclipse-cache.properties      in the target directory.      User property: downloadSources
    eclipseDownloadSources      Deprecated. use downloadSources
      Enables/disables the downloading of source attachments. Defaults to false.      DEPRECATED - use downloadSources      User property: eclipse.downloadSources
    eclipseProjectDir      Eclipse workspace directory.      User property: eclipse.projectDir
    excludes      List of artifacts, represented as groupId:artifactId, to exclude from the      eclipse classpath, being provided by some eclipse classPathContainer.
    forceRecheck      Enables/disables the rechecking of the remote repository for downloading      source/javadoc attachments. Defaults to false. When this flag is true and      the source or javadoc attachment has a status cache to indicate that it is      not available, then the remote repository will be rechecked for a source      or javadoc attachment and the status cache updated to reflect the new      state.      User property: forceRecheck
    jeeversion      The plugin is often capable in predicting the required jee version based      on the dependencies of the project. By setting this parameter to one of      the jeeversion options the version will be locked.      jeeversion      EJB version      Servlet version      JSP version      6.0      3.1      3.0      2.2      5.0      3.0      2.5      2.1      1.4      2.1      2.4      2.0      1.3      2.0      2.3      1.2      1.2      1.1      2.2      1.1      User property: eclipse.jeeversion
    limitProjectReferencesToWorkspace (Default: false)      Limit the use of project references to the current workspace. No project      references will be created to projects in the reactor when they are not      available in the workspace.      User property: eclipse.limitProjectReferencesToWorkspace
    linkedResources      A list of links to local files in the system. A configuration like this      one in the pom :      <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-eclipse-plugin</artifactId>       <configuration>       <linkedResources>       <linkedResource>       <name>src/test/resources/oracle-ds.xml</name>       <type>1</type>       <location>C://jboss/server/default/deploy/oracle-ds.xml</location>       </linkedResource>       </linkedResources>       </configuration>      </plugin>      will produce in the .project :      <linkedResources>       <link>       <name>src/test/resources/oracle-ds.xml</name>       <type>1</type>       <location>C://jboss/server/default/deploy/oracle-ds.xml</location>       </link>      </linkedResources>
    manifest (Default: ${basedir}/META-INF/MANIFEST.MF)      The relative path of the manifest file      User property: eclipse.manifest
    packaging      The project packaging.      User property: project.packaging
    preferStandardClasspathContainer (Default: false)      If set to true, the standard execution environment matching the compiler      settings is set as JRE. If set to false, the JRE matching the configured      compiler-plugin executable or JAVA_HOME is selected by name, if it is      configured in the workspace.      User property: eclipse.preferStandardClasspathContainer
    projectNameTemplate      Allows configuring the name of the eclipse projects. This property if set      wins over addVersionToProjectName and addGroupIdToProjectName You can use      [groupId], [artifactId] and [version] variables. eg.      [groupId].[artifactId]-[version]      User property: eclipse.projectNameTemplate
    projectnatures      List of eclipse project natures. By default the      org.eclipse.jdt.core.javanature nature plus the needed WTP natures are      added. Natures added using this property replace the default list.      <projectnatures>       <projectnature>org.eclipse.jdt.core.javanature</projectnature>
      <projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>      </projectnatures>
    skip (Default: false)      Skip the operation when true.      User property: eclipse.skip
    sourceExcludes      List of exclusions to add to the source directories on the classpath. Adds      excluding='' to the classpathentry of the eclipse .classpath file.      [MECLIPSE-104]
    sourceIncludes      List of inclusions to add to the source directories on the classpath. Adds      including='' to the classpathentry of the eclipse .classpath file.      Java projects will always include '**/*.java'
      Ajdt projects will always include '**/*.aj'
      [MECLIPSE-104]
    testSourcesLast (Default: false)      Whether to place test resources after main resources. Note that the      default behavior of Maven version 2.0.8 or later is to have test dirs      before main dirs in classpath so this is discouraged if you need to      reproduce the maven behavior during tests. The default behavior is also      changed in eclipse plugin version 2.6 in order to better match the maven      one. Switching to 'test source last' can anyway be useful if you need to      run your application in eclipse, since there is no concept in eclipse of      'phases' with different set of source dirs and dependencies like we have      in maven.      User property: eclipse.testSourcesLast
    useProjectReferences (Default: true)      When set to false, the plugin will not create sub-projects and instead      reference those sub-projects using the installed package in the local      repository      Required: Yes      User property: eclipse.useProjectReferences
    workspace      This eclipse workspace is read and all artifacts detected there will be      connected as eclipse projects and will not be linked to the jars in the      local repository. Requirement is that it was created with the similar wtp      settings as the reactor projects, but the project name template my differ.      The pom's in the workspace projects may not contain variables in the      artefactId, groupId and version tags. If workspace is not defined, then an      attempt to locate it by checking up the directory hierarchy will be made.      User property: eclipse.workspace
    wtpapplicationxml (Default: false)      Must the application files be written for ear projects in a separate      directory.      User property: eclipse.wtpapplicationxml
    wtpContextName      JEE context name of the WTP module. ( ex. WEB context name ). You can use      'ROOT' if you want to map the webapp to the root context.      User property: wtpContextName
    wtpdefaultserver      What WTP defined server to use for deployment informations.      User property: eclipse.wtpdefaultserver
    wtpmanifest (Default: false)      Must the manifest files be written for java projects so that that the jee      classpath for wtp is correct.      User property: eclipse.wtpmanifest
    wtpversion (Default: none)      The version of WTP for which configuration files will be generated. The      default value is 'none' (don't generate WTP configuration), supported      versions are 'R7', '1.0', '1.5' and '2.0'      User property: wtpversion