Errata

Java Performance

Errata for Java Performance

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page xiii
Contact Us (last phrase)

The link to the book's page is wrong, it is pointing to https://oreil.ly/java-performance-2e which is another book.

Note from the Author or Editor:
Fixed link, and it now redirects to the correct page.

Luan Kevin Ferreira  Oct 04, 2021  Oct 05, 2021
Safari Books Online
1
Part 1, paragraph "Choosing a GC algorithm"

In caption "Figure 1-3. Actual versus average CPU usage (CMS)"
CMS should be replaced by G1 GC to match the description in the picture

Note from the Author or Editor:
Fixed in the final edit.

Dmitry Zinkevich  Sep 12, 2019  Feb 11, 2020
Printed
Page 57
5th and 6th paragraphs

A few numbers in the explanation here are incorrect, and one sentence needs to be removed. Here are how the two paragraphs should read:

The e1000g1 interface is a 1,000 MB interface; it is not utilized very much (0.33%) in this example. The usefulness of this tool (and others like it) is that it calculates the utilization of the interface. In this output, 225.7 KBps of data are being read, and 176.2 KBps of data are being written over the interface. Doing the division for a 1,000 MB network yields the 0.33% utilization figure, and the nicstat tool was able to figure out the bandwidth of the interface automatically.

Tools such as typeperf or netstat will report the amount of data read and written, but to figure out the network utilization, you must determine the bandwidth of the interface and perform the calculation in your own scripts. Be sure to remember that the bandwidth is measured in bits per second (bps), although tools generally report bytes per second (Bps). In this example, 225.7 KBps are read and 172.6 KBps are written, a total of 3.26 million bits. Dividing by the interface speed yields a utilization rate that rounds to 0.33%. So there is no magic to nicstat (or similar) tools; they are just more convenient to use.

Scott Oaks
 
Jun 28, 2020 
Printed, PDF, Safari Books Online
Page 96
the second list

Original:
• -XX:NonNMethodCodeHeapSize=N: for the nonmethod code
• -XX:ProfiledCodeHapSize=N for the profiled code
• -XX:NonProfiledCodeHapSize=N for the nonprofiled code

Modification:
extra ":" should be removed on the first item
ProfiledCodeHapSize => ProfiledCodeHeapSize
NonProfiledCodeHapSize => NonProfiledCodeHeapSize

Note from the Author or Editor:
As indicated, the bullets should be

-XX:NonMethodCodeHeapSize=N
-XX:ProfiledcodeHeapSize=N
-XX:NonProfiledCodeHeapSize=N

党文亮  Jul 19, 2020 
PDF
Page 107
2nd paragraph

In the section named "G1 GC Allocation of Humongous Objects", we should give example of 512KB instead of 512MB as 512KB is half the size of region.

Note from the Author or Editor:
This is fixed in the edited version of the book.

Abhishek Garg  Aug 24, 2019  Feb 11, 2020
Printed, PDF, Safari Books Online
Page 109
the last line

“)” doesn't have corresponding “(”

Note from the Author or Editor:
In the first line of the last paragraph on page 109, add a ( before the If:

(If you compile the JVM...

党文亮  Aug 03, 2020 
Printed, PDF, Safari Books Online
Page 112
2nd line of 2nd paragraph

"In 2011, Intel introduced Advanced Vector Extensions (AVX2) for the Sandy Bridge (and later) chips"

"AVX2" should be "AVX"?

AVX was first supported by Sandy Bridge in 2011
AVX2 was first supported by Haswell in 2013

Note from the Author or Editor:
Change the second sentence of the second paragraph to read:

In 2013, Intel introduced Advanced Vector Extensions 2 (AVX2) for the Haswell (and later) chips.

党文亮  Aug 03, 2020 
Printed, PDF, Safari Books Online
Page 113
last paragraph

“In absolute terms, saving 34 MB in this example is unlikely to make a huge difference”

34MB should be 35MB or 36MB?
(46.5MB - 10.7MB = 35.8MB)

Note from the Author or Editor:
In last paragraph, change 34 to 36:

In absolute terms, saving 36 MB in this example is unlikely to make a huge difference.

党文亮  Aug 15, 2020 
Printed, PDF, Safari Books Online
Page 116
footnote

AOC => AOT

Note from the Author or Editor:
In the footnote, please change "AOC" to "AOT".

党文亮  Aug 06, 2020 
Printed, PDF, Safari Books Online
Page 125
2nd item of the bottom list

"If the average response time is more important than the outliers (i.e., the 90th%) response time), a nonconcurrent collector may yield better results."

")" after "%" should be removed


Note from the Author or Editor:
In 2nd bullet of page 125, remove ) after 90th%

* If the average response time is more important than the outliers (i.e., the 90th% response time), a nonconcurrent collector may yield better results.

党文亮  Aug 21, 2020 
Printed, PDF, Safari Books Online
Page 127
last paragraph

missing ")" at the end

Note from the Author or Editor:
Add missing parenthesis at end of last paragraph on page 127.

{This occurs using multiple threads.)

党文亮  Aug 21, 2020 
Printed, PDF, Safari Books Online
Page 136
2nd paragraph of "Average CPU Usage and GC"

"Most of the time, only the application threads are running, consuming 50% of the total CPU."

50% should be 25%, as shown in the figure 5-2

Note from the Author or Editor:
Yes, should read "consuming 25% of the total CPU."

党文亮  Sep 09, 2020 
Printed, PDF, Safari Books Online
Page 137
first paragraph and figure 5-3

"The application thread starts by using 50% of the total CPU"
"When that thread finishes, CPU usage drops to 50%, and so on."

50% should be 25%, as shown in figure 5-3
_______

"that thread also consumes an entire CPU, bringing the total up to 75%."

But the peak cpu usage in figure 5-3 is 50%, the figure should be updated

Note from the Author or Editor:
The figure is actually correct, but the text should read:

The application thread setarts by using 25 of the total CPU. Eventually, it has created enough garbage for a G1 GC background thread to kick in; that thread also consumes an entire CPU, bringing the total up to 50%. When that thread finishes, CPU usage drops to 25% and so on.

党文亮  Sep 09, 2020 
Printed, PDF, Safari Books Online
Page 140
5th paragraph

“On a virtual machine running primarily a single JVM, the default initial heap will be only one-quarter of the memory assigned to the virtual machine.”


"initial heap" should be "maximum heap"

Note from the Author or Editor:
Yes, change initial heap to maximum heap.

党文亮  Aug 25, 2020 
Printed, PDF, Safari Books Online
Page 149
first paragraph

“-Xlog:help:”
extra colon at the end

Note from the Author or Editor:
Yes, please change -Xlog:help: to -Xlog:help

党文亮  Sep 10, 2020 
Printed, PDF, Safari Books Online
Page 155
the JDK 11 GC log

The JDK 11 GC log is different from the JDK 8 GC log.
In JDK 8: the overall occupancy of the heap is reduced from 280122K to 66610K
In JDK 11: the occupancy of old generation is reduced from 280122K to 66610K

These numbers are the same, but the information here is not the same. And in a minor GC, the occupancy of old generation should not be reduced. So there must be something wrong.

Note from the Author or Editor:
The lines set in courier fond at the top of page 155 should read like this. I've put in all the lines, but only lines 3 and 6 are changed. Also I've put in the proper number of spaces here, but of course the alignment here is wrong because it is is displaying in a variable-width font. If the data is copy/pasted, it should align as in the book.

[17.805s][info][gc,start ] GC(4) Pause Young (Allocation Failure)
[17.806s][info][gc.heap ] GC(4) PSYoungGen: 227938K->14463K(264128K)
[17.806s][info][gc,heap ] GC(4) PSOldGen: 30799K->52147K(348568K)
[17.806s][info][gc,metaspace ] GC(4) Metaspace: 3743K->3743K(1056768K)
[17.806s][info][gc ] GC(4) Pause Young (Allocation Failure)
280M->66M(613M) 16.932ms
]17.806s][info][gc,cpu ] User=0.05s Sys=0.00s Real=0.02s

党文亮  Oct 04, 2020 
Printed, PDF, Safari Books Online
Page 156
the last line of JDK 11 log

"User=4.446s" => "User=4.44s"

4.44s comes from the previous GC log
and the number here is formatted to two decimal places

Note from the Author or Editor:
In the last line of the callout, change 4.446s to 4.44s.

党文亮  Oct 06, 2020 
Printed, PDF, Safari Books Online
Page 158
4th paragraph

calculation mistake: 1.94% => 1.04%

Note from the Author or Editor:
Yes, please change 1.94 to 1.04.

党文亮  Sep 17, 2020 
Printed, PDF, Safari Books Online
Page 160
Table 6-2

the last line of the table:
end heap size increased and percent time in GC also increased
so I guess that you intended to use 4.8% instead of 8.8% because the time-ratio goal is 5%

Note from the Author or Editor:
In the last line of Table 6-2, change 8.8% to 4.8%

党文亮  Oct 06, 2020 
Printed, PDF, Safari Books Online
Page 162
4th paragraph

78M => 78MB

Note from the Author or Editor:
Yes, please chamge 78 M to 78 MB.

党文亮  Sep 18, 2020 
Printed, PDF, Safari Books Online
Page 167
last paragraph

how is 16MB calculated?
I found: 3200M - 1964M - 1222M = 14M

and in JDK 11 log, the heap usage didn't change: "3791M->3791M(3983M)"
if I add Eden,Survior and Old, I get 1222 + 142 + 1834 = 3198, it's different from the JDK 8 log.

where is the problem?

Note from the Author or Editor:
The line in courier font (3rd from the bottom of the callout) reading
3791M->3791M(3983M) 124.390ms
should be
1222M->144M(1220M)

Then the first two sentences of the last paragraph should be
Notice that the entire heap usage has been reduced by more than just the 1,222 MB removed from eden. This is easier to see in the JDK 8 log, since the JDK 11 log doesn't display the occupancy of the old generation in this log cycle.

党文亮  Oct 09, 2020 
Printed, PDF, Safari Books Online
Page 168
6th paragraph

"This is triggered primarily four times"

four => five

Note from the Author or Editor:
The sentence should read:

This is triggered primarily in five cases:

党文亮  Oct 09, 2020 
Printed, PDF, Safari Books Online
Page 182
2nd paragraph

"Unless those trade-offs are acceptable, take care not to set the CMSInitiatingOccupancyFraction higher than the amount of live data in the heap, plus at least 10% to 20%."

"higher" should be "lower"

党文亮  Oct 11, 2020 
Printed, PDF, Safari Books Online
Page 189
first paragraph

"The total allocation in this period is 1.59 KB"
It would be more clear to say:
"The total allocation outside TLABs in this period is 1.59 KB"

党文亮  Oct 12, 2020 
Printed, PDF, Safari Books Online
Page 190
first paragraph

10,336 => 10,368

In GC log, it's 10368B.

党文亮  Oct 12, 2020 
Printed, PDF, Safari Books Online
Page 190
3rd paragraph

"and 1.1% of the TLABs were wasted from the free space in retired TLABs."

1.1% waste come from 3 parts (the same as per thread log), not only free space in retired TLABs.

related OpenJDK 11 source code:
src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp ('publish' function)

Note from the Author or Editor:
end the sentence after wasted:

1.1% of the TLABs were wasted.

党文亮  Oct 13, 2020 
Safari Books Online
194
table 6-4

"The minimum of half of all memory, or all memory: 160 MB"

":" might be "-" (minus)?

Note from the Author or Editor:
In table 6-4, the first line should read

The minimum of half of all memory or all memory - 160MB

党文亮  Oct 14, 2020 
Printed, PDF, Safari Books Online
Page 199
2nd paragraph

The 90th% time of Throughput GC is 60ms.
In the 2nd paragraph: "lots of outliers with a response time of more than 50 milliseconds"
So, which number should be changed?

And, what does "Tabout" mean? Is it typo for "about"?

Note from the Author or Editor:
In the second sentence of the paragraph, change 50 milliseconds to 60 milliseconds. in the next sentence, change Tabout to about.

党文亮  Oct 04, 2020 
Printed, PDF, Safari Books Online
Page 276
“Unbounded queues” part

LinkedBlockedingQueue => LinkedBlockingQueue

Note from the Author or Editor:
Change as indicated

党文亮  Nov 30, 2020 
Printed, PDF, Safari Books Online
Page 283
4th paragraph

outer loop => inner loop

Note from the Author or Editor:
In fourth paragraph, change "outer loop" to "inner loop".

党文亮  Dec 04, 2020 
Printed, PDF, Safari Books Online
Page 283
5th paragraph

The fourth thread takes a longer time than the first thread.

Note from the Author or Editor:
Second to last paragraph should read:

Now the simple partitioning of the ThreadPoolExecutor will be at a disadvantage. The thread calculating the last partition of the array will take a very long time to complete, much longer than the time spent by the first thread operating on the first partition. Once that first thread is finished, it will remain idle: everything must wait for the final thread to complete its long task.

党文亮  Dec 04, 2020 
Printed, PDF, Safari Books Online
Page 285
sample code

There is no integer in the sample code, but the previous paragraph said there will be "a collection containing a series of integers".

Note from the Author or Editor:
Should say:
Given a collection of a series of strings

党文亮  Dec 06, 2020 
Printed, PDF, Safari Books Online
Page 285
2nd paragraph

ForkJoinPoolClass => ForkJoinPool class
('ForkJoinPool' with constant width)

Note from the Author or Editor:
<code>ForkJoinPool</code> class

党文亮  Dec 06, 2020 
Printed, PDF, Safari Books Online
Page 287
4th paragraph

diifferent => different

Note from the Author or Editor:
Correct spelling

党文亮  Dec 07, 2020 
Printed, PDF, Safari Books Online
Page 319
2nd paragraph

“Then at time T5, the third socket is ready...”
T5 => T6

Note from the Author or Editor:
Should read:
Then at time T6, the third socket is ready

党文亮  Jan 02, 2021 
Printed
Page 323
1st paragraph

The paragraph refers to parsing JSON as "marshalling" and to serializing JSON as "unmarshalling". This is reversed. "Marshalling" is serializing objects into a string and "unmarshalling" is parsing the string and create an object from it.

Note from the Author or Editor:
Yes, the definitions are backwards. The last two sentences of the first paragraph of this section should read:

If the output is a Java object, the process is called unmarshalling; if the data is processed as it is read, the process is called parsing. The reverse--producing JSON strings from other data--is called marshalling.

Richard Metzler  May 27, 2020 
Printed, PDF, Safari Books Online
Page 325
2nd paragraph

“...implementation of the standard JSON parsing (JSON-P) API...”
JSON-P stands for JSON Processing instead of JSON parsing.
(https://javaee.github.io/jsonp/index.html)

Note from the Author or Editor:
standard JSON parsing should be
standard JSON processing

党文亮  Jan 05, 2021 
Printed, PDF, Safari Books Online
Page 329
4th paragraph

SLQ:2003 => SQL:2003

Note from the Author or Editor:
SLQ:2003 should be SQL:2003

党文亮  Jan 06, 2021 
Printed, PDF, Safari Books Online
Page 340
first paragraph

“..calling the commit() method at the end of each while loop...”

there is no while loop.

Note from the Author or Editor:
Should read:
calling the commit() method in each iteration of the for loop

党文亮  Jan 16, 2021 
Printed, PDF, Safari Books Online
Page 340
table 11-1

rows 3: 400,448 => 400,896

Note from the Author or Editor:
rows 3: 400,448 => 400,896

党文亮  Jan 17, 2021 
Printed, PDF, Safari Books Online
Page 341
last paragraph

setTransaction() => setTransactionIsolation()

Note from the Author or Editor:
setTransaction() => setTransactionIsolation()

党文亮  Jan 23, 2021 
Printed, PDF, Safari Books Online
Page 357
bottom sample code

inner for loop:
for (Date date = allDates)
“=” should be ":"
for (Date date : allDates)

Note from the Author or Editor:
for (Date date = allDates)
“=” should be ":"
for (Date date : allDates)

党文亮  Feb 05, 2021 
Printed, PDF, Safari Books Online
Page 366
last paragraph

“Hence, two identical strings of 16 characters will occupy 44 (or 52) bytes each before they are deduplicated for a total of 80 bytes”

each string will occupy 40(or 48) bytes.(16 + 24 = 40)

Note from the Author or Editor:
The final sentences on p 366 and continuing onto page 367 should read:

In Java 11 (assuming the string is composed of 8-bit bytes and not wide characters), two identical strings of 16 bytes will occupy 40 (or 52) bytes each, for a total of 80 (or 92) bytes; after deduplication, they will occupy 64 (or 76) bytes.

党文亮  Feb 14, 2021 
Printed, PDF, Safari Books Online
Page 383
first paragraph

”in two ways: first, you can set the system property -Djava.security​.egd=file:/dev/urandom.“

where is the second way? or it's just the "third option" described in the next paragraph?

Note from the Author or Editor:
Change the first full paragraph on page 383 to start:

The second way to set this option is by changing this line in $JAVA_HOME/jre/lib/security/java.security

党文亮  Mar 15, 2021 
Printed, PDF, Safari Books Online
Page 385
the example code and table 12-8

the 2nd line of for loop in testJavaCC should be:
”l += a / nTrials;“

”given 10,000 trials and 10,000 values.“
should be:
”given 10,000 trials and 1000 values.“

the first three table headers of table 12-8 should be:
testJavaJavaJava calcJavaJava calcJava
instead of:
calculateError Calc Random(this is for the first edition)

in the next paragraph:
numberOfTrials => nTrials
numberOfLoops => nValues

Note from the Author or Editor:
In code fragment, change
l += 50 - a
to
l += a / nTrials

The table headers are fine as is.

In the next paragraph, change variable names as mentioned, and also change the operator to an *:
(nTrials * nLoops)

党文亮  Mar 20, 2021 
Printed, PDF, Safari Books Online
Page 386
2nd paragraph

”In that case, the latter goal is more important“
should be:
”In that case, the former goal is more important“


Note from the Author or Editor:
Change latter to former

党文亮  Mar 20, 2021 
Printed, PDF, Safari Books Online
Page 398
two calc methods

Fix code indention:

public int calc() {
IntegerInterface a3 = () -> { return 3; };
IntegerInterface a2 = () -> { return 2; };
IntegerInterface a1 = () -> { return 1; };
return a3.getInt() + a2.getInt() + a1.getInt();
}
=>
public int calc() {
IntegerInterface a3 = () -> { return 3; };
IntegerInterface a2 = () -> { return 2; };
IntegerInterface a1 = () -> { return 1; };
return a3.getInt() + a2.getInt() + a1.getInt();
}


public void calc() {
return a1.get() + a2.get() + a3.get();
}
}
=>
public void calc() {
return a1.get() + a2.get() + a3.get();
}
}

Note from the Author or Editor:
IN the fifth code line at the top of the page, remove the extra space before the r in return

The final code callout has an extra line with a {. It should be
.... Similarly for the other interfaces....
public void calc() {
return a1.get() + a2.get() + a3.get();
}

The line with return (now the 2nd-to-last line) needs 4 space indentation.

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 400
3rd paragraph

"test whether its first character is A"
=>
"test whether its first character is not A"

Note from the Author or Editor:
Change 3rd paragraph as indicated

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 400
the bottom code

the calcArray method accepts two parameters, but the calls to this method in calcEager method passed three parameters

Note from the Author or Editor:
Change the code callout at the bottom of page 400 to this:

@Benchmark
public void calcEager(Blackhole bh) {
ArrayList<String> al1 = calcArray(al, (s) -> s.charAt(0) != 'A');
ArrayList<String> al2 = calcArray(al1, (s) -> s.charAt(1) != 'A');
ArrayList<String> al3 = calcArray(al2, (s) -> s.charAt(2) != 'A');
ArrayList<String> al4 = calcArray(al3, (s) -> s.charAt(3) != 'A');
String answer = al4.get(0);
bh.consume(answer);
}

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 401
2nd paragraph

"The eager implementation processes only 18,278 of those"
should be:
"The lazy implementation processes only 18,278 of those"

Note from the Author or Editor:
Change 2nd paragraph to read
The lazy implementation processes only 18,273 of those

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 401
table 12-12

what does "Iterator/findFirst" mean?
there is no findFirst call in eager implementation

Note from the Author or Editor:
In table 12-12, change the rows to be
Filter
Iterator

党文亮  May 15, 2021 
Page 404
2nd paragraph

“it takes only 1 ± .600 ms seconds to serialize and 0.85 ± 0.2 μs to deserialize.”
do you mean(two modifications):
“it takes only 1 ± 0.6 ms seconds to serialize and 0.85 ± 0.2 ms to deserialize.”
?

Note from the Author or Editor:
Remove the word "seconds" so that it is
It takes only 1 +/- .6 ms to serialize

党文亮  Feb 13, 2022 
Printed, PDF, Safari Books Online
Page 405
first paragraph

“the object creates and stores a sorted map of prices keyed by date of all the prices between start and end”
what is “start” and “end”?

Note from the Author or Editor:
IN first paragraph, first line should read
When the history for a stock is constructed for a given symbol s, the object creates and stores a sorted map of prices keyed by data of all the prices between firstDate and lastDate.

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 405
3rd paragraph

“Because all of the lazily initialized fields can be calculated from the prices array”
=>
"Because all of the lazily initialized fields can be calculated from the prices map"

Note from the Author or Editor:
Change 3rd paragraph to
Because all of the lazily initialized fields can be calculated from the prices map

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 406
first paragraph

“So far, the example saves about 15% of the total time to serialize and deserialize the object”
total time before = 19.1 + 16.8 = 35.9
total time after = 16.7 + 14.4 = 31.1
saved time percentage = (35.9-31.3)/35.9 = 13.37%
so "15%" should be "13%"

Note from the Author or Editor:
In first paragraph change 15% to 13%

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 406
4th paragraph

"Still, notice that making the histogram field transient has also saved about 13% in the size of the data"

data size before = 785395 bytes
data size after = 754227 bytes
saved data percentage = (785395 - 754227) / 785395 = 3.97%
so "13%" shold be "4%"

Note from the Author or Editor:
In 4th paragraph on page 406, change 13% to 4%

党文亮  May 15, 2021 
Printed, PDF, Safari Books Online
Page 407
first paragraph

"The zipPrices() method serializes the map of prices to a byte array and...."
zipPrices() => makeZippedPrices()

Note from the Author or Editor:
Change zipPrices to makeZippedPrices

党文亮  May 15, 2021 
Page 416
the InitialSurvivorRatio entry

“Increase this if short-lived objects are being promoted into the old generation too frequently.”

Increasing this will reduce the survivor space size. How can this behavior prevent short-lived objects from being promoted?

Note from the Author or Editor:
Reword as:
If objects are being promoted into the old generation too frequently, decrease this value (to increase the survivor space size).

党文亮  Jun 19, 2021 
Page 416
the MinSurvivorRation entry

"Decreasing this value reduces the maximum size of the survivor spaces (and vice versa)."

Decreasing => Increasing

Note from the Author or Editor:
Change as indicated

党文亮  Jun 19, 2021 
Page 417
3rd flag

-XX:+DisableExplicitGC>
=>
-XX:+DisableExplicitGC

Note from the Author or Editor:
Change as indicated

党文亮  Jun 08, 2021 
Page 419
table A-6

duplicate “-XX:G1MixedGCCountTarget=N” entry

Note from the Author or Editor:
Remove duplicate entry

党文亮  Jun 22, 2021 
Page 422
table A-12

-XX:+StartFlightRecorder => -XX:StartFlightRecording

Note from the Author or Editor:
Change as indicated

党文亮  Jun 28, 2021