5

I have a container running a Spring Boot microservice. I am using openjdk version "1.8.0_212" under OpenJDK Runtime Environment (IcedTea 3.12.0) (Alpine 8.212.04-r0) When I use -XX:+PrintFlagsFinal flag and print the JVM parameters I expected to see

-XX:+UseParallelGC as true

But to my surprise none of the 4 collectors (-XX:+UseSerialGC,-XX:+UseParallelGC,-XX:+UseConcMarkSweepGC,–XX:+UseG1GC) were active.

Shown below is my dockerfile:

FROM openjdk:8-jdk-alpine
ADD  ./demo-0.0.1-SNAPSHOT.jar /usr/src/factorial/
WORKDIR /usr/src/factorial
EXPOSE 8080
CMD java $JAVA_OPTIONS -jar demo-0.0.1-SNAPSHOT.jar

I'm running this using:

  docker run -d --rm --name factorialorialContainer --memory='512m' --cpus=2 -p 8080:8080 -e JAVA_OPTIONS="$(cat /Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/$3)" suleka96/factorial:latest

The flags_base.txt

-Xms512m -Xmx512m -XX:+PrintFlagsFinal -version

This is part of the output of -XX:+PrintFlagsFinal

     intx UnguardOnExecutionViolation               = 0                                   {product}
     bool UnlinkSymbolsALot                         = false                               {product}
     bool Use486InstrsOnly                          = false                               {ARCH product}
     bool UseAES                                    = true                                {product}
     bool UseAESIntrinsics                          = true                                {product}
     intx UseAVX                                    = 2                                   {ARCH product}
     bool UseAdaptiveGCBoundary                     = false                               {product}
     bool UseAdaptiveGenerationSizePolicyAtMajorCollection  = true                                {product}
     bool UseAdaptiveGenerationSizePolicyAtMinorCollection  = true                                {product}
     bool UseAdaptiveNUMAChunkSizing                = true                                {product}
     bool UseAdaptiveSizeDecayMajorGCCost           = true                                {product}
     bool UseAdaptiveSizePolicy                     = true                                {product}
     bool UseAdaptiveSizePolicyFootprintGoal        = true                                {product}
     bool UseAdaptiveSizePolicyWithSystemGC         = false                               {product}
     bool UseAddressNop                             = true                                {ARCH product}
     bool UseAltSigs                                = false                               {product}
     bool UseAutoGCSelectPolicy                     = false                               {product}
     bool UseBMI1Instructions                       = true                                {ARCH product}
     bool UseBMI2Instructions                       = true                                {ARCH product}
     bool UseBiasedLocking                          = true                                {product}
     bool UseBimorphicInlining                      = true                                {C2 product}
     bool UseBoundThreads                           = true                                {product}
     bool UseCLMUL                                  = true                                {ARCH product}
     bool UseCMSBestFit                             = true                                {product}
     bool UseCMSCollectionPassing                   = true                                {product}
     bool UseCMSCompactAtFullCollection             = true                                {product}
     bool UseCMSInitiatingOccupancyOnly             = false                               {product}
     bool UseCRC32Intrinsics                        = true                                {product}
     bool UseCodeCacheFlushing                      = true                                {product}
     bool UseCompiler                               = true                                {product}
     bool UseCompilerSafepoints                     = true                                {product}
     bool UseCompressedClassPointers               := true                                {lp64_product}
     bool UseCompressedOops                        := true                                {lp64_product}
     bool UseConcMarkSweepGC                        = false                               {product}
     bool UseCondCardMark                           = false                               {C2 product}
     bool UseContainerSupport                       = true                                {product}
     bool UseCountLeadingZerosInstruction           = true                                {ARCH product}
     bool UseCountTrailingZerosInstruction          = true                                {ARCH product}
     bool UseCountedLoopSafepoints                  = false                               {C2 product}
     bool UseCounterDecay                           = true                                {product}
     bool UseDivMod                                 = true                                {C2 product}
     bool UseDynamicNumberOfGCThreads               = false                               {product}
     bool UseFPUForSpilling                         = true                                {C2 product}
     bool UseFastAccessorMethods                    = false                               {product}
     bool UseFastEmptyMethods                       = false                               {product}
     bool UseFastJNIAccessors                       = true                                {product}
     bool UseFastStosb                              = true                                {ARCH product}
     bool UseG1GC                                   = false                               {product}
     bool UseGCLogFileRotation                      = false                               {product}
     bool UseGCOverheadLimit                        = true                                {product}
     bool UseGCTaskAffinity                         = false                               {product}
     bool UseHeavyMonitors                          = false                               {product}
     bool UseHugeTLBFS                              = false                               {product}
     bool UseInlineCaches                           = true                                {product}
     bool UseInterpreter                            = true                                {product}
     bool UseJumpTables                             = true                                {C2 product}
     bool UseLWPSynchronization                     = true                                {product}
     bool UseLargePages                             = false                               {pd product}
     bool UseLargePagesInMetaspace                  = false                               {product}
     bool UseLargePagesIndividualAllocation         = false                               {pd product}
     bool UseLinuxPosixThreadCPUClocks              = true                                {product}
     bool UseLockedTracing                          = false                               {product}
     bool UseLoopCounter                            = true                                {product}
     bool UseLoopInvariantCodeMotion                = true                                {C1 product}
     bool UseLoopPredicate                          = true                                {C2 product}
     bool UseMathExactIntrinsics                    = true                                {C2 product}
     bool UseMaximumCompactionOnSystemGC            = true                                {product}
     bool UseMembar                                 = false                               {pd product}
     bool UseMontgomeryMultiplyIntrinsic            = true                                {C2 product}
     bool UseMontgomerySquareIntrinsic              = true                                {C2 product}
     bool UseMulAddIntrinsic                        = true                                {C2 product}
     bool UseMultiplyToLenIntrinsic                 = true                                {C2 product}
     bool UseNUMA                                   = false                               {product}
     bool UseNUMAInterleaving                       = false                               {product}
     bool UseNewLongLShift                          = false                               {ARCH product}
     bool UseOSErrorReporting                       = false                               {pd product}
     bool UseOldInlining                            = true                                {C2 product}
     bool UseOnStackReplacement                     = true                                {pd product}
     bool UseOnlyInlinedBimorphic                   = true                                {C2 product}
     bool UseOprofile                               = false                               {product}
     bool UseOptoBiasInlining                       = true                                {C2 product}
     bool UsePSAdaptiveSurvivorSizePolicy           = true                                {product}
     bool UseParNewGC                               = false                               {product}
     bool UseParallelGC                             = false                               {product}
     bool UseParallelOldGC                          = false                               {product}
     bool UsePerfData                               = true                                {product}
     bool UsePopCountInstruction                    = true                                {product}
     bool UseRDPCForConstantTableBase               = false                               {C2 product}
     bool UseRTMDeopt                               = false                               {ARCH product}
     bool UseRTMLocking                             = false                               {ARCH product}
     bool UseSHA                                    = false                               {product}
     bool UseSHA1Intrinsics                         = false                               {product}
     bool UseSHA256Intrinsics                       = false                               {product}
     bool UseSHA512Intrinsics                       = false                               {product}
     bool UseSHM                                    = false                               {product}
     intx UseSSE                                    = 4                                   {product}
     bool UseSSE42Intrinsics                        = true                                {product}
     bool UseSerialGC                               = false                               {product}
     bool UseSharedSpaces                           = false                               {product}
     bool UseSignalChaining                         = true                                {product}
     bool UseSquareToLenIntrinsic                   = true                                {C2 product}
     bool UseStoreImmI16                            = false                               {ARCH product}
     bool UseStringDeduplication                    = false                               {product}
     bool UseSuperWord                              = true                                {C2 product}
     bool UseTLAB                                   = true                                {pd product}
     bool UseThreadPriorities                       = true                                {pd product}
     bool UseTransparentHugePages                   = false                               {product}
     bool UseTypeProfile                            = true                                {product}
     bool UseTypeSpeculation                        = true                                {C2 product}
     bool UseUnalignedLoadStores                    = false                               {ARCH product}
     bool UseVMInterruptibleIO                      = false                               {product}
     bool UseXMMForArrayCopy                        = true                                {product}
     bool UseXmmI2D                                 = false                               {ARCH product}
     bool UseXmmI2F                                 = false                               {ARCH product}
     bool UseXmmLoadAndClearUpper                   = true                                {ARCH product}
     bool UseXmmRegToRegMoveAll                     = true             

After running

jcmd [pid] VM.flags

I am getting the below output which also does not specify a collector:

-XX:CICompilerCount=2 -XX:InitialHeapSize=536870912 -XX:MaxHeapSize=536870912 -XX:MaxNewSize=178913280 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=178913280 -XX:OldSize=357957632 -XX:+StartAttachListener -XX:+UseCompressedClassPointers -XX:+UseCompressedOops 

What Is happening here? Is there anything I'm doing wrong?

Suleka_28
  • 2,761
  • 4
  • 27
  • 43
  • 2
    interesting. I can re-produce, I was sure it will be `SerialGC` - because you use it inside a container and memory under `2GB` (and 2 CPUs), I assume it's just some logging broken for `PrintFlagsFinal` and `PrintCommandLineFlags`; because I can not reproduce it in jdk-13... – Eugene Feb 25 '20 at 19:50
  • 1
    plz don't close it as a duplicate and read it carefully first (even better try, if you can) – Eugene Feb 25 '20 at 19:52
  • 2
    Don't overstate things. The claim in your title is obviously false, otherwise nothing would work. What you mean is that you can't *print* it. – user207421 Feb 25 '20 at 20:34
  • @Eugene when I perform 'jcmd 1 VM.flags' I am not seeing that it is using serialGC. I edited the question to put the full result of running the command. – Suleka_28 Feb 25 '20 at 23:28
  • @Eugene I closed it as a duplicate because the duplicate gave the exact answer to this problem: the printout of the flags does not indicate the choice of garbage collector. This is a duplicate question. You should not have reopened it. – RealSkeptic Feb 26 '20 at 09:48
  • @RealSkeptic at least 7 more people did not agree with you, by voting the accepted answer. And IMO, no, its not a duplicate. – Eugene Feb 26 '20 at 11:16

1 Answers1

10

In JDK 8, if no Use*GC flags are set, and if Parallel GC hasn't been chosen ergonomically, then Serial GC is used.

The fix for JDK-8068582 automatically turns on -XX:+UseSerialGC in such cases since JDK 9.

apangin
  • 92,924
  • 10
  • 193
  • 247
  • as seen in the log it says that UseSerialGC is also false – Suleka_28 Feb 25 '20 at 22:02
  • 2
    @Suleka_28 Yes, because you haven't set it manually. That's what I say in my answer: if you see no `Use*GC` options set, it means that Serial GC is used. JDK 9+ solves this confusion by automatically setting exactly one of `Use*GC` options, see [JDK-8068582](https://bugs.openjdk.java.net/browse/JDK-8068582) for details. – apangin Feb 25 '20 at 22:06
  • After performing 'jcmd 1 VM.flags' it gives me this output: -XX:CICompilerCount=2 -XX:InitialHeapSize=536870912 -XX:MaxHeapSize=536870912 -XX:MaxNewSize=178913280 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=178913280 -XX:OldSize=357957632 -XX:+StartAttachListener -XX:+UseCompressedClassPointers -XX:+UseCompressedOops Even if it is not listed here are you saying that it is using SerialGC? – Suleka_28 Feb 25 '20 at 23:25
  • 2
    @Suleka_28 Yes. The JDK bug I've already linked twice, explicitly says that: "The GC setup code assumes that if non of the Use*GC flags is true we should be using SerialGC. But in that case we don't set UseSerialGC to true." – apangin Feb 25 '20 at 23:42
  • @apagin I did go through the link, the reason I kept asking is that I originally noticed this because I was monitoring the latency values of the microservice when using different collectors. Explicitly setting Serial collector for the application and not specifying a collector and running it gave vastly different latency values. That is why I wanted to know what the collector was set to by default. – Suleka_28 Feb 26 '20 at 03:47
  • 2
    As discussed in [How to determine which GC I use?](https://stackoverflow.com/q/54862460/2711488), i.e. [this answer](https://stackoverflow.com/a/54872064/2711488), you can use the memory pool names as reported by JMX as a heuristic to identify the GC algorithm. – Holger Feb 26 '20 at 08:04