La presentazione tenuta da Davide Del Vecchio e Nino Guarnacci in occasione del Codemotion a Roma del 5 marzo 2011 - http://www.codemotion.it/
Nato sotto gli auspici della GPL v.2 l'Open Jdk è il laboratorio per il futuro di Java : perchè dovreste usarlo, come attivare le caratteristiche più innovative e quali sono gli aspetti più interessanti non solo per la parte sound...
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Open Jei Di Key not only for DJ's
1. Open Jei Di Key not only for DJ's
ATTENZIONE: Questo intervento è stato
reciclato tra quelli scartati.
Successivamente ripescato (tipo Pupo a
Sanremo) per la triste rinuncia di qualcuno a
tenere lo stra-atteso intervento:
SKRONDO il linguaggio del futuro
per qualcuno
Nino Guarnacci davide.delvecchio@gmail.com
Davide Del Vecchio nino.guarnacci@oracle.com
sabato 5 marzo 2011
2. Java Language
Most Popular Language in the World
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
3. Java Around Us
Servers Desktop Embedded TV Mobile Card
BD-J
Java EE JavaFX Java TV MSA
Java SE Java ME Java Card
Java Language
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
4. JCP Evolve & Adapt Java
Community Development of
Java Technology Specifications
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
5. Java Priorities
Grow Developer Base
Grow Adoption
Increase Competitiveness
Adapt to change
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
6. Vision Java
• Drive continued investment in the Java
platform across a range of servers and
devices
• Fuel further innovation in the Java
platform, including JavaFX
• Continue supporting developer
community, open source, and JCP
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
7. Standard Edition
• Rapid delivery of JDK 7 Oracle
• Converge features of HotSpot and JRockit
JVM:
– Leading performance
– Monitoring and management
– Automated performance tuning
– Virtualized servers
– Efficient garbage collection
– Deterministic, real time behavior
• Focus on Serviceability and Interoperability
• Continue support for all leading OS platforms
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
8. Contributors
• Oracle Is Committed to the Best Open-Source Java
Implementation
• Backed by Some of the biggest names in software:
–“Oracle and IBM Collaborate to Accelerate Java
Innovation Through OpenJDK”
–“Oracle and Apple Announce OpenJDK Project for Mac
OS X”
–Red Hat and Sun (Oracle) Collaborate to Advance Open
Source Java Technology
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
9. OJDK 7 Fetaures
• InvokeDynamic byte code + supporting features
– Multi-lang support
• Small Language Enhancements (Project ”Coin”)
• Lambda Expressions (“Closures”) JSR 335
• SDP and SCTP Support
• New I/O APIs
– Filesystem, async I/O
• JVM Improvements
– Performance and serviceability
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
10. Project Coin
Strings in switch
• Binary integral literals and underscores in numeric literals
• Multi-catch and more precise rethrow
• try-with-resources statement
• Improved type inference for generic instance creation (diamond)
• Simplified varargs method invocation
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
11. String in Switch
p ublic String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
String typeOfDay;
switch (dayOfWeekArg) {
case "Monday":
typeOfDay = "Start of work week";
break;
case "Tuesday":
case "Wednesday":
case "Thursday":
typeOfDay = "Midweek";
break;
case "Friday":
typeOfDay = "End of work week";
break;
case "Saturday":
case "Sunday":
typeOfDay = "Weekend";
break;
default:
throw new IllegalArgumentException("Invalid day of the week: " +
dayOfWeekArg);
}
return typeOfDay;
}
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
12. Binary integral literals and underscores in numeric
literals
// An 8-bit 'byte' literal.
byte aByte = (byte)0b00100001;
// A 16-bit 'short' literal.
short aShort = (short)0b1010000101000101;
long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = ! 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
13. Multi-catch and more precise rethrow
catch (IOException ex) {
logger.log(ex);
throw ex;
catch (SQLException ex) {
logger.log(ex);
throw ex;
}
Open JDK7
catch (IOException|SQLException ex) {
logger.log(ex);
throw ex;
}
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
14. try-with-resources statement
static void copy(String src, String dest) throws IOException {
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dest);
try {
byte[] buf = new byte[8 * 1024]; • java.nio.channels.FileLock
• javax.imageio.stream.ImageInputStream
int n;
• java.beans.XMLEncoder
while ((n = in.read(buf)) >= 0) • java.beans.XMLDecoder
out.write(buf, 0, n); • java.io.ObjectInput
} finally { • java.io.ObjectOutput
out.close(); • javax.sound.sampled.Line
} • javax.sound.midi.Receiver
} finally { • javax.sound.midi.Transmitter
• javax.sound.midi.MidiDevice
in.close(); • java.util.Scanner
} • java.sql.Connection
} • java.sql.ResultSet
• java.sql.Statement
Open JDK7
static void copy(String src, String dest) throws IOException {
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest)) {
byte[] buf = new byte[8192];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
Nino Guarnacci <--> Davide Del Vecchio
sabato 5 marzo 2011
15. Linguaggi per la JVM (http://is-research.de/info/
vmlanguages)
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
16. Perché tutto questo
affollamento?
Perché viene scelto di usare il
runtime di java per
implementare nuovi linguaggi
anche strutturalmente diversi?
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
17. Multi Language JVM JRuby (Antonio Cangiano
Luglio 2010)
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
18. Vantaggi dell’uso di una JVM
Velocità :
> performance (JIT che ottimizza le
chiamate, nessun interprete)
> Uso della memoria efficiente (GC,
nessuna allocazione tramite primitive
malloc)
> multiprocessor scaling (pervasive
threading)
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
19. Vantaggi per Java di questa
apertura
In molti casi è utile disporre di un
linguaggio con una semantica diversa
>Testing (è molto comodo scrivere un
test per Java in Groovy)
>DSL (espressività ..)
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
20. Strumenti
Che cosa abbiamo a
disposizione per
implementare nuovi
linguaggi e migliorare
le perfomance di quelli
che ci sono?
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
21. Javax.scripting Solo un Driver
Le JSR 223 (Scripting for the java platform) tenevano conto
della necessità di interazione con diversi linguaggi di
scripting : poteva essere dichiarato uno scripting engine
ed invocato da codice java alla maniera in cui si carica un
driver JDBC
ScriptEngineManager scriptEngineMgr = new
ScriptEngineManager(); ScriptEngine jsEngine =
scriptEngineMgr.getEngineByName("JavaScript");
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
22. VM multilinguaggio
> Supporto per linguaggi dinamici
> Perfomance paragonabili a quelle native
> Estendibile senza hacking o riuso
Il codice scritto in un linguaggio dovrebbe:
Invocare codice scritto in un linguaggio
diverso
Manipolare oggetti nativi di un
linguaggio diverso
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
23. Come avviene l’invocazione di un
metodo?
Pensiamo ad
un’invocazione di un
metodo come ad un
trasferimento di
messaggi
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
24. Come avviene un’invocazione
(bytecode)
identificati scope receiver? dispatch?
vo
invokestatic class no no
invokespecia class yes no
l
invokevirtual class yes yes
invokeinterfa interface yes yes
ce
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
25. Un’ulteriore ditta di trasporto
Invokedynamic
obj.helloText
⇓
methodVisitor.visitMethodInsn(
INVOKEDYNAMIC,
"InvokeDynamic",
"dyn:getProp:helloText",
"(Ljava/lang/Object;)Ljava/lang/
Object;");
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
26. Perché è meglio?
Separa il lavoro in due fasi: link-time
and
invocation-time
• Quanto più possiamo spendere su
link-time è meglio
• nel caso precedente l’id della
proprietà è fisso e quindi può essere
risolto a link-time
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
27. Come la reflection? NO
Java può fare questo con le
reflection API (che sono
quelle adoperate per
l’implementazione dei
linguaggi visti prima)
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
28. Reflection Basics
public static Object invoke(Object
targetObject, String methodName,
Object[] arguments, Class<?>[]
signature)
return method.invoke(targetObject,
arguments);
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
29. No Wrapping
Non ci sono tutte le
restrizioni
dell’invocazione di
metodi
• Nessun wrapping di
eccezione
• La verifica delle
condizioni di accesso è
fatta a tempo di
creazione
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
30. Piccole patch per la JVM
ufficiale
>invokedynamic (indy.patch)
> method handles (meth.patch)
> small Java language changes
(langtools/meth.patch)
> interface injection (inti.patch)
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
31. JSR 292
JSR-292 fornisce la specifica per la il bytecode perla
dynamic method invocation, più un meccanismo
per l’evoluzione del codice
> Quello che adesso è presente è il
• invokedynamic bytecode
• Application-defined linkage (and re-linkage)
• Method handles
• Un’infrastruttura generale per "code pointers"
• Interface injection
Davide Del Vecchio <--> Nino Guarnacci
sabato 5 marzo 2011
32. Nino Guarnacci Davide Del Vecchio
nino.guarnacci@oracle.com davide.delvecchio@gmail.com
lo SKRONDO
sabato 5 marzo 2011