java overview and java se 6 what's new - netbeans · pdf filejava overview and java se 6...

105
Java Overview and Java SE 6 What's New Max Li Campus Ambassador in HKUST Gigi Li Campus Ambassador in CUHK Sun Microsystems, Inc.

Upload: vuonghuong

Post on 14-Mar-2018

234 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java Overview andJava SE 6 What's New

Max LiCampus Ambassador in HKUST

Gigi LiCampus Ambassador in CUHK

Sun Microsystems, Inc.

Page 2: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

All About

Page 3: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What's the meaning of

??

■ Andy Bechtolsheim ■ Vinod Khosla■ Scott McNealy■ Bill Joy

Page 4: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What is

doing ??

Page 5: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Product of Sun• Computer servers and workstations

(based on Sun's SPARC, AMD's Opteron, Intel's Xeon)

• Storage systems(Sun StorageTek 5800 System, Sun Fire X4500 storage server, SAM-QFS filesystem)

• Operating System(Solaris OS)

• Developer tools(Netbeans, Sun Studio)

• Platform& Standards(Java, Java SE, Java EE, Java ME)

• Database Management Systems(JavaDB, PostgreSQL for Solaris, MySQL)

• Others(Sunspot, Systems Management, Mozilla Suite, Identity Manager etc.)

Page 6: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel
Page 7: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Campus Ambassador

ProgramTowards

Education

Page 8: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel
Page 9: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Sun Academic Initiative Program

Take the online course of Sun technologies for FREE! based on 2 websites: http://learningconnection.sun.com http://sunsite.scut.edu.cn

Nearly 60% discount for the Sun Certificate !!! SCJP: Sun Certified Java Programmer SCSA: Sun Certified System Administration for the Solaris Operating System Sun Certified Developer for Sun Application Server Sun Certified Engineer for Sun Directory Server

Page 10: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

share the most to the world !

Page 11: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

BUILDING A COMMUNITY

Opening Day: June 14, 2005

Page 12: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

November 13rd. 2006

Page 13: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

http://mustang.dev.java.net

Page 14: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

CommunitySun Developer Community of China http://developers.sun.com.cn

Open Technology Community http://www.opentech.org.cn

NetBeans Community http://www.netbeans.org

OpenSolaris Community http://www.opensolaris.org

Java Community http://www.java.net

OpenJDK Community http://community.java.net/OpenJDK

Page 15: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java and NetbeansJava and NetbeansOverviewOverview

Page 16: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What is Java?

Page 17: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java is a Brand!Compatibility is Guaranteed!

Page 18: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java is a Programming Language!

Page 19: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java is a Platform!

Page 20: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Where is Java?

Page 21: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java is Everywhere

NASA’s Mars Exploration Rovers

NASA's Mars Exploration Rovers

Page 22: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java is FREE Software

Page 23: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java is being used by everyone!

Printers

TVsWebcams

STBs

Cash Registers

PDAs

Telescopes

Medical Equipment

Lottery Terminals

Consumer Electronics

Game Consoles

Robots

Page 24: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel
Page 25: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java Dominates in Financial Services

Source: Forresters’ Architect Survey on European Financial Industry in Jan 2008http://www.sun.com/aboutsun/media/analyst/european_fsa.pdf

Page 26: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java Community

Page 27: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java.net: The Source for Java Technology Collaboration

• What it is:> Web-based community for Java

developers> Open, collaborative Java

development> Communities with common

interests (java gaming)

• Active and vibrant> 175,000+ members> 2,200+ projects> 19 Java communities> 74 hosted JUGs> 100 RSS feeds> Blogs, Wikis, Javapedia

Page 28: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel
Page 29: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Mark Your Calendar!

San Francisco: May 6-9, 2008

Page 30: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

NetBeans

Page 31: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What Is NetBeans?

There are two answers...#1: It is an award-winning IDE

• For Java developers (but we're adding more languages...)

• Free, open-source - http://www.netbeans.org

• Large (and growing) community of users that can help.

Page 32: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What Is NetBeans?

#2: It is a Platform

• For building rich client applications that will run on any operating system that supports a standard JVM.

• Provides a rich framework of windows, menus, tool bars, actions, etc.

• Used for building a wide variety of applications

Page 33: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What Is NetBeans?

Seeing is believing

• Quick Examples> Minex

Page 34: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What makes NetBeans the best?

1. Ant Based Project System2. Friendly Editor3. Powerful J2EE Support4. Visual J2ME Development5. An integrated Profiler6. Collaboration tools

Page 35: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What makes NetBeans the best? (cont.)

7. Spectacular GUI Builder (Project Matisse)

8. Refactoring support9. CVS support10. Java BluePrints Solution Catalog11. Module Development Support12. Update Center

Page 36: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

What's New In NetBeans 6.0?

• Code editor enhancements• Ruby, JRuby, & Ruby on Rails support • Easier installation and upgrading• Swing GUI data binding • Integrated profiling, profiling “points”• Integrated visual web features• Mobility graphical game builder• SOA & UML enhancements• Netbeans platform enhancements

Page 37: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Netbeans 6.0 Resources• Netbeans Product Site: http://www.netbeans.org

> Download: previews, current & past releases of IDE, plugins> Learning: tutorials, technical articles, flash demos> Community: latest news, forums, events, mailing lists

• Netbeans Wiki: http://wiki.netbeans.org/wiki/> Open-source documentation site for Netbeans

• Planet Netbeans: http://www.planetnetbeans.org/> Aggregate for all Netbeans-related blogs

• Source Code: cvs.netbeans.org:/cvs> CVS source code access for Netbeans platform + IDE

Page 38: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

=Opportunity

Go Get It !

Page 39: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Hello World

The Scene Behind Programming with Java

Page 40: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Hello World

public class HelloWorld { public static void main( String[] arg ) { System.out.println( "Hello World" ); }}

Page 41: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Compile “Hello World”

Compile

Page 42: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Compile ...

HelloWorld.java HelloWorld.classCompiler

Page 43: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

javac and g++ ??

• compile to binary bytecode

• resolve all reference as symbolic “handles”

• memory layout is defined upon execution

• compile to binary machine code

• resolve all “pointers” into memory address

• memory layout is defined by compiler

javac g++

Page 44: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

class System

public final class System {

public final static InputStream in = nullInputStream(); public final static PrintStream out = nullPrintStream(); }

System.out.println( "Hello World" );

Handle to PrintStream

object

Page 45: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Problem with Pointers

•Fragile Super-class Problem•Security Problem

Page 46: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Fragile Super-class Problem

Before

After

Although there is no change

in the impl. of B,B is still needed to re-compile

Page 47: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Security Problem

invoke the Hack_Class

routine

Page 48: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

The Hack Class Output

Memory layout of class A

re-construct private variable

Modify the private

constant

Page 49: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Run "Hello World"

Run

Page 50: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Run...

HelloWorld.class

Verifier Interpreter

JVM

Class Loader

Page 51: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Class Loader

Local File SystemClass Namespace

Network-loaded Class Namespace

JVM

HelloWorld.class WorldWideWeb.class

Page 52: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Verifier

• Verify the executing Bytecode comes from different compiler

• No forging pointers

• No violating access restrictions

• No object is accessed with invalid type

Page 53: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

The Entire Process

Page 54: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

♫ How to manage memory without pointer in Java?

♫ Why need manage memory?

How & Why?

Page 55: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Execute ...

public class HelloWorld { public static void main( String[] arg ) { System.out.println( "Hello World" ); }}

String instancePrintStream Method

Page 56: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

class String

public final class String { private final char value[]; private final int offset; private final int count; private int hash;}

Read-onlyimmutable obj

Page 57: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Hello World Modified

public class HelloWorld { public static void main( String[] arg ) { System.out.println( "Hello World" + "~" ); }}

What's happening?

Page 58: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

class String

public final class String { public String concat( String str ) { int otherLen = str.length(); if ( otherLen == 0 ) { return this; } char buf[] = new char[ count + otherLen ]; getChars( 0, count, buf, 0 ); str.getChars( 0, otherLen, buf, count ); return new String( 0, count + otherLen, buf ); }}

return new String,

where is the old one?

Page 59: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Where is the old String?

• Un-referenced ... becomes memory leak?• Deallocated immediately?• Threw into the Trash?

Trash

Page 60: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

The Garbage Collector

• Problem of Explicit malloc() and free()1. Dangling reference2. Memory leak

• GC automatically allocate memory and deallocate memory

• Responsibility:1. Allocating memory2. Ensuring referenced object in memory3. Recovering memory no longer in use

Page 61: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Simple GC

class ReferenceCounter {

public:

static void NewReference( Object *obj ) {

++obj->reference_count;

}

static void ThrowAway( Object *obj ) {

--obj->reference_count;

if ( obj->reference_count == 0 ) {

free( obj );

}

}

};

Page 62: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

GC Design Choice

• Serial vs Parallel

• Concurrent vs Stop-the-World

• Compact vs Non-compact vs Copying

Tradeoff

Time

Heap Space GC Frequency

Page 63: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

GC Design in JVM

JVMConventional Garbage Collection

Pre-HotSpot:

Post-HotSpot: Exact JVM (JVM 1.2.2)Exact Garbage Collection

JVM 1.3Generational Garbage Collection

Page 64: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Generation Collection

Heap

Young Generation

Old Generation

Page 65: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

The Philosophy

• Most object dies young

• Objects survived in several rounds of GC are important

• Large objects are mostly important

• Few references from older to younger objects exist

Page 66: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Object dies Young??

public int Search( Vector<String> vector, String value ) {

Iterator<String> iter = vector.iterator();

for( int i = 0; iter.hasNext(); ++i ) {

if ( iter.next() == value ) {

return i;

}

}

return -1;

}

Page 67: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Generation Characteristic

• High garbage density

• Occupy small heap space

• Carry frequent GC

• Low garbage density

• Occupy big heap space

• Carry few GC

Young Generation(Minor Collection)

Old Generation(Major Collection)

Page 68: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

How it works?? (young -> old)

Page 69: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java Hotspot Generations

• Young generation

• Old generation

• Permanent generation(e.g. Class, Method objects)

Eden

From ToSurvivor

Big Heap

Page 70: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Hotspot Collectors

• Serial Collector

• Parallel Collector

• Parallel Compacting Collector

• Concurrent Mark-sweep Collector

Page 71: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Serial Collector – young generation

Page 72: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

mark-sweep-compact

slide

Serial Collector – old generation

Page 73: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Parallel Collector – young generation

Page 74: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Parallel Compacting Collector– old generation

Mark phase

● live objects are marked in parallel

Summary phase

● calculate density and find the region worth to compact

dense prefix

dense prefix

Compaction phase

● compaction is not carried in the dense prefix

Page 75: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Concurrent Mark-Sweep Collector– old generation

Page 76: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Concurrent Mark-Sweep Collector

Page 77: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Hotspot Collectors

• Serial Collector-XX:+UseSerialGC

• Parallel Collector-XX:+UseParallelGC

• Parallel Compacting Collector-XX:+UseParallelOldGC

• Concurrent Mark-sweep Collector-XX:+UseConcMarkSweepGC

Page 78: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java Past, Now, and Future

The Evolution Process

Page 79: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java SE Timeline

Page 80: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

History

• 1995 (1.0) – The First Public Release

• 1997 (1.1) – Nested Class AddedSupport for Function Objects

• 2001 (1.4) – Assertions AddedSupport for Verifying Codes

Page 81: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

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

Page 82: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Sample Code

int sum = 0;

List<Integer> list = Arrays.asList(1, 2, 3);

for (int i: list)sum += i;

System.out.println(“sum = “ + sum);

Generics

Auto-boxing

For-loop

Page 83: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Generics

• New code> Example 1

> Example 2

List<String> list = new LinkedList<String>(); list.add("hello world"); String msg = list.iterator().next();

public void print(Hashtable<String, Integer> list) {

for (String key: list.keySet())

System.out.println(key + “ = “

+ list.get(key));

}

Page 84: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Autoboxing of Primitive Types

• Old code

• New Code

ArrayList list = new ArrayList(); list.add(0, new Integer(42)); int total = ((Integer)list.get(0)).intValue();

ArrayList<Integer> list = new ArrayList<Integer>(); list.add(0, 42); int total = list.get(0);

Page 85: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Enhanced for Loop

• Old code

• New code

Iterator iter = hashSet.iterator(); while (iter.hasNext()) {

Object obj = iter.next(); ... }

for (Object obj: hashSet) { ... }

Page 86: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Variable Argument List

• Old code

• New code

public void printArgs(String[] args) { ...

public void printArgs(String... args) { for (String a: args)

System.out.println(a);

printArgs(x, y);printArgs(x, y, z);

Page 87: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

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, Stabilityhttp://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10

Page 88: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

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

Page 89: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Java Object Header

Mark Word (32/64bits)

Class Metadata Address (32/64bits)

Array Length (32//64bits)

2 words for Object, 3 words for Arrays

Page 90: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Mark Word

Page 91: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Light Weight Locking-unlocked

Thread stack

Execution Stack

Method Activation

Lock Record

hash + age | 01

Object Header

Page 92: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Light Weight Locking-locked

Thread stack

Execution Stack

Method Activation

hash + age | 01

Stack Pointer

Object Header

Displaced Mark Word

CAS

Page 93: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Light Weight Locking-contented

Memory

Mutex

OR

Condition Variable

Mutex Pointer

Object Header

Page 94: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Light Weight Locking-recursed

Thread stack

Execution Stack

Method Activation

hash + age | 01

Stack Pointer

Object Header

CAS

recursion count

Page 95: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

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

Page 96: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Biased Locking

Object Header

CAS

Light Weight Locking

Page 97: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

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

Page 98: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Revoking ...

Thread stack

Execution Stack

Method Activation

Displaced Mark

Stack Pointer

Object Header

walk

Update

Page 99: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Comparing the Lockings

Light Weight Locking

lock (CAS) :unlock (CAS)

lock (CAS) :unlock (CAS)

Biased Locking

lock (CAS) :unlock (TAB)

lock (TAB) :unlock (TAB)

Execution

Page 100: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

JavaSE 7

Page 101: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel
Page 102: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Where Are We?

JDK 5 2004/9/30JDK 6 2006/12/11JDK 7 2008/H2

Page 103: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Future?

Source : Forrestor's Architect Survey on European Financial Industry in Jan 2008

http://www.sun.com/aboutsun/media/analyst/european_fsa.pdf

Page 104: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Further Readingshttp://openjdk.java.net/http://java.sun.com/docs/white/langenv/http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdfhttp://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#langhttp://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10http://java.sun.com/performance/reference/whitepapers/6_performance.html

Page 105: Java Overview and Java SE 6 What's New - NetBeans · PDF fileJava Overview and Java SE 6 What's New Max Li ... defined by compiler javac g++. class System ... • Serial vs Parallel

Q & A