java overview and java se 6 what s new
play

Java Overview and Java SE 6 What's New Max Li Campus Ambassador in - PowerPoint PPT Presentation

Java Overview and Java SE 6 What's New Max Li Campus Ambassador in HKUST Gigi Li Campus Ambassador in CUHK Sun Microsystems, Inc. All About What's the meaning of ? ? Andy Bechtolsheim Vinod Khosla Scott McNealy Bill Joy


  1. Generation Characteristic Young Generation Old Generation (Minor Collection) (Major Collection) • High garbage • Low garbage density density • Occupy small heap • Occupy big heap space space • Carry frequent GC • Carry few GC

  2. How it works?? (young -> old)

  3. Java Hotspot Generations • Young generation Eden From To Survivor • Old generation Big Heap • Permanent generation (e.g. Class, Method objects)

  4. Hotspot Collectors • Serial Collector • Parallel Collector • Parallel Compacting Collector • Concurrent Mark-sweep Collector

  5. Serial Collector – young generation

  6. Serial Collector – old generation slide mark-sweep-compact

  7. Parallel Collector – young generation

  8. Parallel Compacting Collector – old generation Mark phase ● live objects are marked in parallel dense prefix Summary phase ● calculate density and find the region worth to compact dense prefix Compaction phase ● compaction is not carried in the dense prefix

  9. Concurrent Mark-Sweep Collector – old generation

  10. Concurrent Mark-Sweep Collector

  11. Hotspot Collectors • Serial Collector -XX:+UseSerialGC • Parallel Collector -XX:+UseParallelGC • Parallel Compacting Collector -XX:+UseParallelOldGC • Concurrent Mark-sweep Collector -XX:+UseConcMarkSweepGC

  12. Java Past, Now, and Future The Evolution Process

  13. Java SE Timeline

  14. History • 1995 (1.0) – The First Public Release • 1997 (1.1) – Nested Class Added Support for Function Objects • 2001 (1.4) – Assertions Added Support for Verifying Codes

  15. Java SE 5 Language Features • Autoboxing and unboxing • Enhanced for loop • Static import • Typesafe enumerations • Variable argument list • Generics • Annotations (metadata) http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#lang

  16. Sample Code int sum = 0; Generics List<Integer> list = Arrays.asList(1, 2, 3); for (int i: list) Auto-boxing sum += i; For-loop System.out.println(“sum = “ + sum);

  17. Generics • New code > Example 1 List<String> list = new LinkedList<String>(); list.add("hello world"); String msg = list.iterator().next(); > Example 2 public void print(Hashtable<String, Integer> list) { for (String key: list.keySet()) System.out.println(key + “ = “ + list.get(key)); }

  18. Autoboxing of Primitive Types • Old code ArrayList list = new ArrayList(); list.add(0, new Integer(42)); int total = ((Integer)list.get(0)).intValue(); • New Code ArrayList<Integer> list = new ArrayList<Integer>(); list.add(0, 42); int total = list.get(0);

  19. Enhanced for Loop • Old code Iterator iter = hashSet.iterator(); while (iter.hasNext()) { Object obj = iter.next(); ... } • New code for (Object obj: hashSet) { ... }

  20. Variable Argument List • Old code public void printArgs( String[] args ) { ... • New code printArgs(x, y); printArgs(x, y, z); public void printArgs(String... args) { for (String a: args) System.out.println(a);

  21. Java SE 6 Top 10 Feature • Web Services • Scripting • Database • More Desktop APIs • Monitoring Management • Compiler Access • Pluggable Annotations • Desktop Deployment • Security • The -lities: Quality, Compatibility, Stability http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10

  22. Synchronization Optimization • All modern JVMs incorporate light-weight locking > Avoid associating an OS mutex / condition variable (heavy-weight lock) with each object • Effective because most locking is uncontended – not competed by threads

  23. Java Object Header Mark Word (32/64bits) Class Metadata Address (32/64bits) Array Length (32//64bits) 2 words for Object, 3 words for Arrays

  24. Mark Word

  25. Light Weight Locking -unlocked hash + age | 01 Execution Stack Method Activation Object Header Lock Record Thread stack

  26. Light Weight Locking -locked Stack Pointer Execution Stack CAS Method Activation Object Header hash + age | 01 Displaced Mark Word Thread stack

  27. Light Weight Locking -contented Mutex Pointer Mutex OR Condition Variable Object Header Memory

  28. Light Weight Locking -recursed Stack Pointer Execution Stack CAS Method Activation Object Header hash + age | 01 recursion count Thread stack

  29. Observation • Most lockings are not only uncontended, but performed repeatedly by the same thread >> Make it cheap for a single thread to reacquire a lock can be an optimization

  30. Biased Locking CAS Object Header Light Weight Locking

  31. What happens when Revoke? • Fallback to light weight locking • Need to wait for Global Safepoint ( No bytecode is executing ) • Thread stack is walked and lock record is enumerated • Update Object Header when object is locked

  32. Revoking ... walk Stack Pointer Execution Stack Update Method Activation Object Header Displaced Mark Thread stack

  33. Comparing the Lockings Light Weight Locking Biased Locking lock (CAS) lock (CAS) : : unlock (CAS) unlock (TAB) lock (CAS) lock (TAB) : : unlock (CAS) unlock (TAB) Execution

  34. JavaSE 7

Recommend


More recommend