Things you need to know about JVM (that matter in Scala)
Things you need to know about JVM (that matter in Scala)
About the Book
Scala is not Java and Java is not Scala. This may sound obvious, as both languages have different goals and features. They might generate different byte code and even when they do something apparently the same, they might still generate byte code differently. What matters is that at the end of the day you need to understand JVM very well in order to get to the bottom of what is happening, or why something was implemented the way it was. Even in Scala.
This book isn't aiming to be an exhaustive list of what you should know about JVM - that topic is so extensive that you could write a whole book (or books) on that. To meet that requirement you're better of to grab a book on preparing for Java Programmer Certified Professional exam.
The goal of my book is to give you enough knowledge to understand why certain decisions were made by Scala creators and library writers. Why we can do certain things and cannot do other. How it affects functional programming. Give you some general ideas about how things work, so that if you wanted to learn more, you would at least know what to google for.
The book is available as an early access including all the intended content. The author is continuing its editing as he believes that improvements should be driven by the feedback. If you found something that you believe could be done better, feel free to contact the author to help him make the book better for everyone.
The "main" version is PDF while EPUB is experimental, so please consider it a bonus.
Table of Contents
- What is JVM
-
- Primitives and references
- Operations
- More about memory
-
- Stack
- Heap
- Boxing and unboxing
- JVM types vs Scala type hierarchy
- Exceptions
- Classpath and ClassLoaders
-
- Classpath exception
- Classes
-
- What a normal class is made of
-
- Constructor
- Methods
- Inheritance
- Access control
- What are objects (modules)
- Parametric classes
-
- Type parameters and type erasure
- Issues with type erasure
- @specialized
- Functions vs methods
- case classes and case objects
- sealed hierarchies
- AnyVals
- Threads
-
- Parallel vs concurrent
-
- Concurrency
- Parallelism
- M:N threads
- JVM’s Threads
-
- Interruption and canceling
- synchronized and @volatile
- sleep, wait and notify
- Can we avoid concurrency pitfalls?
- Garbage collectors
-
- GC root
- How JVM cleans up memory
-
- Mark and sweep
- Memory fragmentation
- Generations, Serial GC and parallel GC
- Concurrent Mark-Sweep
- Garbage First (G1)
- Zero Garbage Collection (ZGC)
- No GC at all?
- GCs beyond HotSpot
- Value specially treated by memory management
- Memory leaks
- How does memory matter for Scala?
- Reflection
-
- What Class[_] knows?
- How to obtain Class[_]?
- Best thing since sliced bread?
- Reflection in Scala
- Why it matters that you understand reflection?
- Optimizations
-
- HotSpot
- C1 and C2
-
- Architecture Description (.ad files)
- Observing JIT at work
-
- Printing assembly
- Printing compilation and inlining
- JITWatch
- Microbenchmarks
-
- Example benchmark
- Flight Recorder and Java Mission Control
- async -profiler and flame graph
- Some of the optimizations done by HotSpot
-
- Inlining
- Loop unrooling
- Dead code elimination
- Escape analysis
- Mono-, Bi- and Megamorphism and devirtualization
- On Stack Replacement (OSR)
- Reflection and optimizations
- More about JVM optimizations
- Optimizations beyond JVM
-
- Memory alignment
- Branch prediction
- Why it matters to have some idea about JIT?
- Tooling and ecosystem
-
- Official tools
-
- javap and scalap
- jdb
- jps
- jstat and jstatd
- jstack
- jcmd
- Other official tools
- Third-party tools
-
- jEnv
- Dependency management and building
- Printing all JVM flags
- Summary
- Appendix: JVM flags
-
- GC and memory flags
-
- Generation-based memory layout and flags
- GC selection
- Memory debugging flags
- JIT flags
-
- Compilation mode selection
- Compilation options
- Compilation debugging
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them