Better HN
topnewbestaskshowjobs
Log inSign up

shipilev

82 karma · joined May 15, 2015 (11y ago) · 11 submissions

[ my public key: https://keybase.io/shipilev; my proof: https://keybase.io/shipilev/sigs/RY8lP1-O2DjS71kZHtD5s0XraPh0XynSyCGw9rh6qrQ ]
Submissions

comment 6y ago · link · parent

The post misleads readers into thinking that JVM runs the GC before exit. It does not.

When I was writing the Epsilon JEP, I meant that it might be futile to have a hundreds-of-ms-long GC cycle, when the program exits very soon anyway, and the heap would be abandoned wholesale. The important bit of trivia is that GC might be invoked long before 'the whole memory' is exhausted. There are several reasons to do this: learning the application profile to size up generations or collection triggers, minimizing the startup footprint, etc. GC cycle then can be seen as the upfront cost that pays off in future. With the extremely short-lived job that future never comes.

Contrived example:

  $ cat AL.java
  import java.util.*;

  public class AL {
       public static void main(String... args) throws Throwable {
          List<Object> l = new ArrayList<>();
          for (int c = 0; c < 100_000_000; c++) {
              l.add(new Object());
          }
          System.out.println(l.size());
      }
  }

  $ javac AL.java

Ooof, 12.5 seconds to run, and about 2 cpu-minutes taken with Parallel:

  $ time jdk11.0.5/bin/java -XX:+UnlockExperimentalVMOptions -Xms3g -Xmx3g -XX:+UseParallelGC -Xlog:gc AL
  [0.015s][info][gc] Using Parallel
  [0.988s][info][gc] GC(0) Pause Young (Allocation Failure) 768M->469M(2944M) 550.699ms
  ...
  [12.281s][info][gc] GC(3) Pause Full (Ergonomics) 1795M->1615M(2944M) 7660.045ms
  100000000

  real 0m12.464s 
  user 1m53.618s
  sys 0m1.087s
Much better with G1, but we still took 11 cycles that accrued enough pauses to affect the end-to-end timing. Plus GC threads took some of our precious CPU.

  $ time jdk11.0.5/bin/java -XX:+UnlockExperimentalVMOptions -Xms3g -Xmx3g -XX:+UseG1GC -Xlog:gc AL
  [0.031s][info][gc] Using G1
  [0.452s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 316M->314M(3072M) 124.119ms
  ...
  [2.518s][info][gc] GC(11) Pause Young (Normal) (G1 Evacuation Pause) 2321M->2324M(3072M) 79.496ms
  100000000

  real 0m2.953s 
  user 0m16.880s
  sys 0m0.872s
Now Epsilon, whoosh, 1.5s end-to-end, and less than 1s of user time, which is probably the only running Java thread itself, plus some OS memory management on allocation path.

  $ time jdk11.0.5/bin/java -XX:+UnlockExperimentalVMOptions -Xms3g -Xmx3g -XX:+UseEpsilonGC -Xlog:gc AL
  [0.004s][info][gc] Using Epsilon
  ...
  [1.387s][info][gc] Heap: 3072M reserved, 3072M (100.00%) committed, 2731M (88.93%) used

  real 0m1.480s
  user 0m0.830s
  sys 0m0.699s
You might think fully concurrent GCs would solve this, and they partially do, by avoiding large pauses. But they still eat CPUs. For example, while Shenandoah is close to Epsilon in doing the whole thing in about 1.7s wall clock time, it still takes quite significant CPU time. Therefore, that benefit is there because machine has spare CPUs to offload that work to.

  $ time jdk11-shenandoah/bin/java -XX:+UnlockExperimentalVMOptions -Xms3g -Xmx3g -XX:+UseShenandoahGC -Xlog:gc AL
  [0.009s][info][gc] Using Shenandoah
  ...
  [0.913s][info][gc] Trigger: Learning 3 of 5. Free (1651M) is below initial threshold (2150M)
  [0.913s][info][gc] GC(2) Concurrent reset 1265M->1267M(3072M) 0.689ms
  [0.914s][info][gc] GC(2) Pause Init Mark 0.111ms
  [1.276s][info][gc] GC(2) Concurrent marking 1267M->1925M(3072M) 361.985ms
  [1.306s][info][gc] GC(2) Pause Final Mark 0.465ms
  [1.306s][info][gc] GC(2) Concurrent cleanup 1924M->1748M(3072M) 0.171ms

  real 0m1.761s 
  user 0m5.688s 
  sys 0m0.633s

comment 7y ago · link · parent

Oracle is in a separate category, no question there.

It was my mistake to mention other vendors in the thread that is about AdoptOpenJDK. I just wanted to show where the AdoptOpenJDK sits in the larger OpenJDK ecosystem: they are important builders and distributors.

comment 7y ago · link · parent

Granted, Oracle does contribute lots of code. As the result, lots of Oracle-created code gets backported too. That said, I see people backport a lot of code/tests that they wrote themselves, and/or with the help of non-Oracle contributors. For example, Red Hat, SAP, Huawei backport a lot of code to maintain the target platforms they own (e.g. AArch64 and PPC), or their components (e.g. diagnostics support, Shenandoah), or their build environments. While I understand the desire to pitch Oracle here, it would be awkward to do so by undervaluing the contributions of others at the same time.

comment 7y ago · link · parent

There are many OpenJDK(-based) distributions out there, mostly built from the OpenJDK {8, 11} Update Releases sources. AdoptOpenJDK provides one of those distributions.

Most of the actual backport work is done by the OpenJDK participants, notably people from Red Hat (like me), SAP, Amazon, Azul and others. Oracle does not participate in OpenJDK 8u/11u directly, opting to maintain their separate tree, from which they build Oracle JDK 8u/11u available under the commercial license. There is also a security collaboration between many companies (OpenJDK Vulnerability Group), which drops its deliverables in relevant source trees.

At one point, I tried to draw this map to show the bird's eye view on the landscape: https://shipilev.net/jdk-updates/map/ -- you can find AdoptOpenJDK there.

What gets people confused is http://openjdk.java.net/ linking to Oracle distribution (either at jdk.java.net, or Oracle site). That might be seen as "OpenJDK providing the binaries", but it is actually not: it links to one of the distribution providers.

comment 7y ago · link · parent

Red Hat also provides binaries built from the unmodified OpenJDK source here: https://adoptopenjdk.net/upstream.html -- which could be downloaded without developer account.

comment 7y ago · link · parent

In tracing collectors, marking (and generally walking the heap in possibly random order) would take a significant amount of time. After marking is done, you may decide to move only a few objects, so the overhead of the copying itself is not that large. Updating the references to all those moved objects might take another bulk of time. These stories get better with attempts to segregate the heaps (generational, recording intra-regions references, etc) somewhat. That comes with associated runtime costs to maintain the metadata to support those partial collections, but on the upside it allows to minimize the amount of work done (again), as it only walks/marks copies/updates the sub-heaps.

I would not agree with the blanket "The stop-the-world pauses in the JVM are typically from compaction". Concurrent marking is done in CMS, G1, Shenandoah, ZGC. [In first two, there are nitty gritty details about young collections that distort the story] -- and that resolves a significant portion of stop-the-world time. Concurrent copying and updating references is done in Shenandoah, ZGC -- that resolves the rest of it.

Of course, you can skip the compact part, and just do a sweep, which frees implementation from dealing with the second part completely. This is not without drawbacks, though: allocation path gets more complicated, fragmentation needs to be dealt with, etc. How far you can get with that, depends on what the use cases really are. As far as I can tell, the damned "CMS concurrent mode failure" caused by heap fragmentation and unwillingness to part with uber-fast bump-ptr allocation paths nudged most JVM people to accept compaction as the go-to answer for reliable GC.

comment 7y ago · link · parent

I agree with you and present even a stronger statement: talking about GC pauses without measuring the actual end-to-end latencies may give the false impression! The overall throughput might look good, but threads might experience bad local latencies all over the place anyway. In Shenandoah project, that is my recurrent argument for capping the pacing stalls and going to STW mode when bounded pacing did not help.

comment 7y ago · link · parent

> throttling pauses are not counted as GC pauses

Yes. All GCs I know employ the negative feedback loops between allocators and GCs. Stop-the-world GCs are on the far side of that spectrum: there, allocation failure induces "throttling" that would not unblock the thread until the GC is over. Even contending on shared allocation lock when requesting the new thread-local allocation buffer can be thought as accidental throttling.

Concurrent GCs are relying on collecting faster than application allocates, but sometimes application allocates way too much anyway. I believe ZGC does the simplest thing in this case: if allocation fails, the allocation is blocked until memory is available (i.e. until current GC cycle is able to recover some memory). Is this also throttling? I think so. Shenandoah does a few other tricks, including diving into STW when concurrent mode fails. To me, this is also the form of throttling.

At the end of the day, I would say that GC pause durations are non-ideal proxies for end-to-end latency. That said, GC pauses do contribute to end-to-end latency very significantly, and so they are not completely meaningless. Their duration should be taken with a fair grain of salt, though, for either Go GC, ZGC, Shenandoah, or whatever else.

comment 7y ago · link · parent

The pause time behavior depends a lot on what is going on in application itself. Shenandoah wiki has a section on that: https://wiki.openjdk.java.net/display/shenandoah/Main#Main-G.... It also depends on the hardware, because the same amount of GC work instruction-wise may translate to drastically different cycle/wall-clock time. Try the same 1 GB heap on large x86 desktop and then on Raspberry Pi! This, unfortunately, makes point benchmark numbers not very relevant, and you would want to see how the particular deployment works. With many applications you can push concurrent GCs down to sub-millisecond range without even trying. With some applications, adjusting the application to avoid pitfalls that inflate pauses helps -- the report mentions a few adjustments like that.

Edit: Ah, I should have mentioned I am one of those Shenandoah devs, and I have never said "your mileage may vary" that often until diving into GC development work :D

comment 11y ago · link · parent

Author's note: Interesting to see this resurfacing after a year. JMH had improved significantly since then, including the release of 1.0.