Upload
dogangoko
View
11.233
Download
2
Tags:
Embed Size (px)
Citation preview
Remember Java EE 5?
2
Ease of Development FocusMajor Revamp of Programming Model
EJB™ 3.0 support for POJOs means less learn, less to code and less to maintain
New Java™ Persistence API makes object/relational mapping cleaner and easier
New and updated Web Services (JAX-WS 2.0 and JAXB 2.0) simplifies SOA implementation
JavaServer™ Faces 1.2 facilitates building Web 2.0 Applications with AJAX
Annotations often eliminates the need for deployment descriptors
Supported by NetBeans™ 5.5 Enterprise PackGet the SDK:
http://java.sun.com/javaee/downloads
History of Enterprise Java
3
JPE Project
J2EE 1.2Servlet, JSP, EJB, JMS, RMI/IIOP
J2EE 1.3CMP,
Connector Architecture
J2EE 1.4Web
Services, Management, Deployment,
Async. Connector
Java EE 5Ease of
Development, Annotations,
EJB 3.0 Persistence
API, New and Updated Web
ServicesEnterpriseJava
Platform
Robustness
Web Services
Ease ofDevelopment
Rightsizing• “Ease of development is good, but…
… the platform still feels too big.”>Feedback: we want less bloat
• Reduce size, without losing focus• Make the platform fit a particular class of applications
well• Increase flexibility of deployment
5
Pruning• Make some components optional• Send a strong message to application developers• Same rules as Java SE apply:
> “pruned now, optional in next release”• Likely candidates for pruning:
>EJB Entity Beans—Replaced by JPA>JAX-RPC—Replaced by JAX-WS>JAXR—Used Infrequently>JSR-88— Used Infrequently, not used by applications
7
Things We Like Withthe Java Language• Automatic Memory Management (GC)• Strong Typing• Object-Oriented• No Pointers• WORA• Run-Time Optimization• Rich Class Library• Static Typing (well, sometimes…)• Simple, Clean and Expressive
Things We Like Withthe JVM• Automatic Memory Management (GC)• Strong Typing• Object-Oriented• No Pointers• WORA• Run-Time Optimization• Rich Class Library• Static Typing (well, sometimes…)• Simple, Clean and Expressive
Languages For the JVM?
http://www.robert-tolksdorf.de/vmlanguages.html
Infiqs, Java+, BDC Scheme, Armed Bear Common Lisp (ABCL), Lili, Jatha, Bigloo, SISC, Lisp, PS3I, Scheme package, HotScheme, webLISP, Jaja, JScheme, Skij, Kawa, Jscheme, LispkitLISP Compiler, Lambda Calculus Interpreter, The UncommonLisp
Interpreter, uts, Grasshopper, Testalgo2, Mapyrus, MaVerickBASIC, CONVERT, JBasic, HotTEA, JavaBasic, COCOA, TSR-80 Model 1 BASIC, StarLogo, AJLogo, Turtle Tracks, rLogo, Yoyo, K.U.Leuven JCHR, TermWare, Drools, XProlog, tuProlog, PROLOG+CG, DGKS Prolog, JLog, Java Internet Prolog, NetProlog, CKI Prolog, JavaLog, Jinni, LLPj, LL, W-Prolog, jProlog, JESS-Java Expers System Shell, javalog, MINERVA, Kiev, Bruce, SmallWorld, SmalltalkJVM, Talks2, Bistro, G, Groovy, Nice, Scala, Anvil,
SmallWorld, SmalltalkJVM, Talks2, Bistro, G, Groovy, Nice, Scala, Anvil, Ephedra, dSelf, Hojo, foo, Correlate, MetaJ, Demeter/Java, Bolero, Sather, PERCobol, Ada,
JGNAT, FScript, Sleep, WLShell, Bambookit, JudoScript, JRuby, ObjectScript, Jickle, Yoix, Simkin, BeanShell, Dawn, DynamicJava, W4F, Netscript, Rhino,
PolyJsp, Resin, Iava, WebL, FESI, iScript, Jython, Pnuts, Yassl, Janino, JAsCo, Join Java, Kanaputs, Jam, JEX, JMatch, Javassist, Jiazzi, ArchJava, MultiJava,
Gilgul, dejay, Guarana, AspectJ, PolyJ, xkjc, Jass, Borneo, GJ, Jamie, Scriptic, OpenJava, Kiev, JavaParty, JAVAR, JAVAB, Pizza, myForth, Delta Forth, FIJI, Misty
Beach Forth, AMPC, Snobol3, Processing, Qexo, Frink, ANTLR, JavaCC, ZigZag, ComponentPascal, JOMP, Tea, Tiger, perljvm, f2j, Oberon, Luck, Occam, E, Assembler
Categories• Precompilers: 10• Tcl: 3• Functional: 6• LISP & Co.: 21• BASIC: 11• Logo: 5• Logic Programming: 19• Eiffel: 1• Smalltalk: 4• Various: 53
• COBOL: 1• Ada: 2• Scripting: 27• Extended Java: 31• Forth: 5• Assemblers: 4
!203
“Big” Changes from Sun• Modularization
>JSR-294>Project Jigsaw>JSR-277
• JVM Support for Dynamic Languages>JSR-292> invokedynamic
• New I/O 2>JSR-203>True asynchronous I/O>new file i/o
13
More “Big” Changes from Sun• Language Changes
>Safe rethrow>Null dereference expressions>Better type inference>Multi-Catch
• Swing Application Framework>JSR-296
• Forward Port of Java 6u10 Features>Java Kernal>Quickstarter>New Applet plug-in
14
“Small” Changes from Sun• SCTP (Stream Control Transmission Protocol)• SDP (Sockets Direct Protocol)• Upgrade Class Loader Architecture• Method for Closing a URLClassLoader• Unicode 5.0 Support• XRender Pipeline for Java2D• Swing Updates
15
“Fast” Changes from Sun• G1 (Garbage First) Garbage Collector
>Shorter pause times>Replaces Concurrent mark and sweep (hopefully)
• Compressed pointer 64 bit VM• MVM-Lite
>Multiple Virtual Machine> Isolation> “kill -9” on a Java application
16
Other Changes• Annotations on Java Types
>JSR-308>Driven by Prof. Michael Ernst and Mahmood Ali>ex. @NonNull
• Concurrency and Collections Updates>JSR-166>Fork/Join>Phasers>LinkedTransferQueue>ConcurrentReferenceHashMap>Fences
17
Not in Java™7 (partial list)• Closures
>No consensus around a single proposal• Reified Generics• 1st Class Properties• Operator Overloading• BigDecimal Syntax• JSR-295 Beans Binding
18
Superpackages
19
superpackage example.bar.lib { // member packages member package example.bar.lib; // member superpackages member superpackage example.bar.lib.net, example.bar.lib.xml; // list of exported types export example.bar.lib.Table; export superpackage example.bar.lib.net; }
JVM Architecture
runtime data areas
method area
class loader subsystem
heapJava
stackspc
registers
native method stacks
execution engine native method
interfacenative method
libraries
invokevirtual• General form:
> invokevirtual TargetObjectType.methodDescriptor> MethodDescriptor:
methodName(ArgTypes) ReturnType
• Very close to Java programming language semantics> Only overloading (and generics) left to javac> Single inheritance, single dispatch, statically typed
• Verifier ensures types are correct
invokevirtual TargetType.method(ArgType) ReturnType
Dynamically Typed Languages• Anything can be passed to a function/method
> No type information at compile time> No type information at byte code generation time (even
when doing Just-in-Time generation)> Type information only at run time
And Here the Troubles BeginConsider a trivial snippet of code in a dynamically typed language:
newSize(c)
// Collection has grown; figure out the next increment
// in size
{
return c.size() * c.growthFactor();
}
And Here the Troubles BeginConsider a trivial snippet of code in a dynamically typed language:
newSize(c)
// Collection has grown; figure out the next increment
// in size
{
return c.size() * c.growthFactor();
}
c.growthFactor()
And Here the Troubles BeginConsider a trivial snippet of code in a dynamically typed language:
newSize(c)
// Collection has grown; figure out the next increment
// in size
{
return c.size() * c.growthFactor();
}
c.growthFactor()
invokevirtual UknownType.growthFactor() UnknownReturnType
And Here the Troubles BeginSolution: synthetic interfaces
newSize(c)
// Collection has grown; figure out the next increment
// in size
{
return
((Interface91)((Interface256) c).size()) *
(Interface91) ((Interface42) c).growthFactor();
}
And Here the Troubles BeginSolution: synthetic interfaces
newSize(c)
// Collection has grown; figure out the next increment
// in size
{
return
((Interface91)((Interface256) c).size()) *
(Interface91) ((Interface42) c).growthFactor();
}
invokeinterface Interface42.growthFactor() Object
Solution: invokedynamic
• Target need not be statically known to implement method descriptor given in instruction> No need for a host of synthetic interfaces
• Actual arguments need not be statically known to match method descriptor> Instead, cast at invocation time to ensure integrity
• Will be added to the Java Virtual Machine as of Java7 (Dolphin)
A loosely typed invokevirtual
invokedynamic Anyclass.growthFactor() Object
invokedynamic, Cont.• The JVM won’t traverse the type hierarchy
> delegated to a plug-in written by the language designer> every language has it’s own rules for inheritance and
delegation> enables multiple inheritance> enables prototype based languages
Only a Partial Solution• No direct support for multiple inheritance or multiple
dispatch> General support is hard—each language has its own rules
• Calling Java platform libraries from scripting languages brings additional problems> How do you resolve overloading?
• However, invokedynamic is a useful primitive in most of these complex scenarios as well
invokedynamic/** * Syntactic marker interface for class- * based dynamic method selection. */package java.dyn;public interface Dynamic { // empty}
// Running example Java code which exercises Draft invokedynamicclass MyCaller { Object myMethod(Object x, Object y, int z) { // x . invokedynamic["alpha",(Object,int)Object] (y, z) return ((Dynamic)x).alpha(y, z); }}
void someMethod() throws X1,X2 { try { /* Something that can throw X1,X2 */ } catch (Throwable e) { logger.log(e); throw e; // Error: Unreported exception Throwable } }
Safe Re-Throw
31
void someMethod() throws X1,X2 { try { /* Something that can throw X1,X2 */ } catch (Throwable e) { logger.log(e); throw e; // Error: Unreported exception Throwable } }
void m() throws X1,X2 { try { /* Something that can throw X1,X2 */ } catch (final Throwable e) { logger.log(e); throw e; // Compiles OK; can throw X1,X2 } }
Safe Re-Throw
31
T x = null;if( a != null ) { B b = a.b(); if( b != null ) { C c = b.c(); if( c != null ) { x = c.x(); } }}
Null-Dereference Expression
32
T x = null;if( a != null ) { B b = a.b(); if( b != null ) { C c = b.c(); if( c != null ) { x = c.x(); } }}
T x = a?.b()?.c()?.x();
Null-Dereference Expression
32
Map<String,Integer> m = new HashMap<String,Integer>();
Better Type Inference
33
Map<String,Integer> m = new HashMap<>();
try { ... }catch( X1 e ) { foo(); }catch( X2 e ) { foo(); }catch( X3 e ) { bar(); }
Multi-Catch
34
try { ... }catch( X1, X2 e ) { foo(); }catch( X3 e ) { bar(); }
void foo(Bar x) { x.fum(); // Potential NullPointerException}
Annotations on Java Types
35
void foo(@NonNull Bar x) { x.fum(); // Statically Checked}
NIO 2
36
import java.nio.file.*;
Path home= Path.get("/home/gus"); Path profile= home.resolve(".bash_profile");
// Backup existing file profile.copyTo(home.resolve(".bash_profile.backup"));
// Append useful stuff to the profile WritableByteChannel ch= profile.newSeekableByteChannel(APPEND); try { appendStuff(ch); } finally { ch.close();}
Concurrency and Collections• Doug Lea, Josh Bloch, et. al• Fork/Join framework• Phasers — Generalized barriers• LinkedTransferQueue — Generalized Queue• ConcurrentReferenceHashMap• Fences — Fine-grained read/write ordering
37
Primary:ClosureLiteral
ClosureLiteral:{ FormalParametersopt => BlockStatementsopt Expressionopt }
Closures
39
public class DeepThought { // { => int } means a function with no arguments and return type int static { => int } answer = { => 42 };
public static void main(String[] args) { int i = answer.invoke(); System.out.println(i);
}}
Closures, further example
41
42
SUN LABS PROJECT:
Maxine Open Source Research VM
• GNU General Public License version 2> License-compatible with OpenJDK™
• Currently builds on JDK 1.6 release• Not a fully compliant Java™ Virtual Machine (yet)
• Alpha release source code:
https://maxine.dev.java.net/
43
SUN LABS PROJECT:
Maxine Platforms
• Supported:> Solaris™ Operating System / SPARC® Technology> Solaris / x64
> Mac OS X / x64
> Xen / x64
• Contemplated:> Xen / x32
> ARM
> PowerPC
> Windows
• Under development:> Solaris OS / x32
> Linux / x64
> Linux / x32
> Mac OS X / x32
44
SUN LABS PROJECT:
Conventional vs. Meta-Circular
C/C++ etc.
JDK
Applications
Java Language
Native
Libraries
C/C++ etc.
ConventionalVM Native
Libraries
Java
Applications
Language
JDKMeta-Circular VM
45
SUN LABS PROJECT:
Meta-Circular VM Design
• The VM is written in the same language it executes
• The VM uses JDK packages and implements their downcalls into the VM
• Built around an optimizing compiler (not an interpreter)
• The optimizing compiler in the VM translates itself
The Lisp Read-Eval-Print-Loop(defun eval (e a) (cond ((atom? e) (assoc e a)) ((atom? (car e)) (cond ((eq (car e) 'quote) (cadr e)) ((eq (car e) 'atom?) (atom? (eval (cadr e) a))) ((eq (car e) 'eq) (eq (eval (cadr e) a) (eval (caddr e) a))) ((eq (car e) 'car) (car (eval (cadr e) a))) ((eq (car e) 'cdr) (cdr (eval (cadr e) a))) ((eq (car e) 'cons) (cons (eval (cadr e) a) (eval (caddr e) a))) ((eq (car e) 'cond) (evcon (cdr e) a)) ('t (eval (cons (assoc (car e) a) (cdr e)) a)))) ((eq (caar e) 'label) (eval (cons (caddr e) (cdr e)) (cons (list (cadar e) (car e)) a))) ((eq (caar e) 'lambda) (eval (caddar e) (append (pair (cadar e) (evlis (cdr e) a)) a))) ) )
47
SUN LABS PROJECT:
Multi-Language Potential
• Fortress• JRuby• Jython• JavaScript• Java FX
• All of the above already have Java implementations• Let's reuse scalable managed runtime investment• No need for Java bytecode (or extensions thereof)