Processing & Properties of Floor and Wall Tiles.pptx
Java8 bench gc
1. Intro to functional programming.
Hidetomo Morimoto
http://github.com/mocchidesu
2015/02/20
2. Brief history of Java
Lamdas / Stream API
Why “functional” language?
Benchmark multi-core
Basic garbage collection
Open JDK / HotSpot VM?
G1GC James Gosling: Father of Java
4. Date Version Highlights
1991 Oak by James Gosling@Sun
Microsystems
Named after oak tree stood
outside his office. For small
PDA device. Slight flavor of C
1996 Jan 23 JDK 1.0 “Oak” sounds similar to “awk”?
1997 Java 1.1 JDBC, reflection, JIT compiler
1998 Java2 (J2SE) Collection framework,
Swing(GUI) API
2000 Java 1.3 JNDI, RMI
2002 Feb. Java 1.4 Regex, JAXP
2004 Sept. Java 1.5 Generics, annotation, enum,
concurrency, varargs
2006 Dec. Java 1.6 Performance tune, JDBC4
2011 July Java 1.7 JVM support dynamic language
(syntax wise, no change)
5. Features
DateTime API (no more new Date(), Calendar.getInstance()!)
Nashborn JavaScript engine ($JAVA_HOME/bin/jjs)
Default method in Interface / Improved concurrent package
Lambda expressions
@FunctionalInterface annotations
Method Reference
java.util.Stream package
Backward Compatibility
Binary compatibility && Behavioral compatibility - Excellent
Source compatibility - Good
6. Lambda is a syntax “sugar” of anonymous class
that has 1 method: Functional Interface.
(Runnable, Comparable, etc.)
7. @Abstract Word Clod for Concurrency
http://www.123rf.com/photo_16617606_abstract-word-cloud-for-concurrency-with-related-tags-and-terms.html
8. Task Parallelism vs. Data Parallelism.
Functional Language approach
Same Idea: MapReduce Google BigTable
(utilize thousands of commodity machines)
10. Sequence of elements from a source that
supports aggregate operations
(Out of 250M people. Pick age 20-30, Living within X miles from LA, male, etc.)
Start with .stream(), chain with intermediate
operators, end with terminal operator.
Intermediate Operator
(filter, map, sorted, distinct, limit)
Terminal Operator
(forEach, collect, reduce, iterator)
11. Developer likes benchmark, hates meeting.
Microbenchmarking framework. JMH
Numerous reasons you don’t do it yourself.
▪ HotSpot VM compiles “hotspot”
▪ VM optimize code flow
Annotation basis
Open JDK
https://github.com/mocchidesu/java8bench
13. Since 1960. Not changed for 50 years.
Only 3 basic algorithms.
Mark & Sweep GC by John McCarthy(1960)
Copy GC by Marvin Minsky (1963)
Reference Counting GC by George E. Collins
(1960)
14. Mark Phase: Flag all the
accessible object. (from root,
register, call stack)
Sweep Phase: Remove
unreferenced.
Pros
Simple / Easy
Cons
Memory Fragmentation
Stop the world (Entire heap
scan)
15. Heap divided into two
equal space (To : From)
Pros
No Memory
Fragmentation
Cons
Overhead of copying.
Requires twice the size.
17. Any of recent GC is the mix of those 3.
Generational GC is an approach.
▪ Young generation
▪ Survivor space (copy gc)
▪ Old / Tenured
18. 90%+ objects are gone immediately
Why do we need to process full GC each time?
19. Let’s divided them up.
If Object survived through GC process one time, promote to Survivor Space
If Object survived XX times, promote to Tenured space.
Young generation GC (Scavenge) happens more often than Tenured space.
20. Garbage First Garbage Collection
Generational
High Throughput
Optimized for Server / Client architecture
Memory compaction
Introduced Java1.7 ver…
21. java –jar
-XX:+UseG1GC (Generational, high throughput, suitable for server-client architecture)
-XX:MaxGCPauseMillis=200
-Xx:InitiatingHeapOccupancyPercent=45
-XX:NewRatio=n (young generation)
-XX:SurvivorRatio=n (eden/survivor space)
-XX:ParallelGCThreads=n (number of cores)
-XX:+ScavengeBeforeFullGC
(UseParallelGC/UseSerialGC/UseConcMarkSweep
GC)
22. Lambda is not only a syntax sugar
It’s a new era of Java
When use? NOW
GC is fun
23. Oracle Java Garbage Collection
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html
Oracle Compatibility Guide for JDK 8
http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-
2156366.html
Lambda Peek under the Hood by Brian Goetz - Java One 2013
http://www.slideshare.net/jaxlondon2012/lambda-a-peek-under-the-hood-brian-
goetz
10 Example of Lambda Expressions and Streams in Java 8
http://javarevisited.blogspot.com/2014/02/10-example-of-lambda-expressions-in-
java8.html