Cool in Java 8, and new in Java 9 - RainFocus · PDF file• Store Interned Strings in CDS...
Transcript of Cool in Java 8, and new in Java 9 - RainFocus · PDF file• Store Interned Strings in CDS...
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
WhatiscoolinJava8andnewin9
AurelioGarcia-RibeyroDirectorofProductManagementJavaPlatformGroupMarch2017
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
SafeHarborStatementThefollowingisintendedtooutlineourgeneralproductdirection.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedforOracle’sproductsremainsatthesolediscretionofOracle.
3
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Introduction
– DirectorProductManagement,JavaPlatformGroup,Oracle– InchargeofmanagingtheproductrequirementsforOracle’sJDKsincejoiningOraclethroughtheSunacquisitionin2010– BeforejoiningOracle,workedatSunMicrosystemsfortheJavaProductManagementteam–MBAfromMITSloanandBachelordegreeinSystemsEngineeringfromUniversidaddeLima
AurelioGarcia-Ribeyro
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Java8 “Oneofthebiggestupdatesevertoamajorlanguage”AndrewBinstock
FormerEditorinChief,Dr.Dobbs ,nowwithJavaMagazine
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Abridged Content List for JDK 8
§ LambdaExpressions§ DefaultMethods§ MethodReferences§ DateTimeAPIs- JSR310
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
AbstractingoverBehaviorCollection<Person> people = ...;
for (Person p : people){if (p.getAge() > 18)
?? How do we remove this person ???}
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
AbstractingoverBehaviorCollection<Person> people = ...;
Iterator<Person> it = people.iterator();while (it.hasNext()) {
Person p = it.next();if (p.getAge() > 18)
it.remove();}
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
AbstractingoverBehaviorinterface Predicate<T> {
boolean test(T t);}
class Collections {public static<T>
void removeIf(Collection<T> coll, Predicate<T> pred) {
...}
}
TheAPIDesignerCouldcreatemethodsinthecollection
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Collection<Person> people = ...;
Collections.removeIf(people, new Predicate<Person>() {
public boolean test(Person p) {return p.getAge() > 18;
}}
});
AbstractingoverBehavior Butthecodetousethenewmethodwouldbebloated
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Collection<Person> people = ...;
Collections.removeIf(people, new Predicate<Person>() {
public boolean test(Person p) {return p.getAge() > 18;
}}
});
AbstractingoverBehavior
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
AbstractingoverBehaviorCollection<Person> people = ...;
Collections.removeIf(people, p -> p.getAge() > 18);
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
AggregateoperationsCollection<Person> people = ...;
int highestWeight = 0;for (Person p : people) {
if (p.getGender() == MALE) {int weight = p.getWeight();highestWeight = max(highestWeight,weight);
}}
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
ParallelismCollection<Person> people = ...;
int highestWeight = people.stream()
.filter(p -> p.getGender() == MALE)
.mapToInt(p -> p.getWeight())
.max();
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Parallelism
class MaxProblem {
final List<Person> people;final int size;
MaxProblem(List<Person> ps) {this.people = ps;size = ps.size();
}
public int solveSequentially() {int max = 0;for (Person p : people) {
if (p.getGender() == MALE) max = Math.max(max, p.getWeight());
}return max;
}
public MaxProblem subproblem(int start, int end) {return new MaxProblem(people.subList(start, end));
}
}
class MaxFinder extends RecursiveAction {
private final MaxProblem problem;int max;
protected void compute() {if (problem.size < THRESHOLD)
sum = problem.solveSequentially();else {
int m = problem.size / 2;MaxFinder left, right;left = new MaxFinder(problem.subproblem(0, m))right = new MaxFinder(problem.subproblem(m, problem.size));forkJoin(left, right);max = Math.max(left.max, right.max);
}}
}
ForkJoinExecutor pool = new ForkJoinPool(nThreads);MaxFinder finder = new MaxFinder(problem);pool.invoke(finder);
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
ParallelismCollection<Person> people = ...;
int highestWeight = people.stream()
.filter(p -> p.getGender() == MALE)
.mapToInt(p -> p.getWeight())
.max();
Collection<Person> people = ...;
int highestWeight = people.parallelStream()
.filter(p -> p.getGender() == MALE)
.mapToInt(p -> p.getWeight())
.max();
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Abridged Content List
§ LambdaExpressions§ DefaultMethods§ MethodReferences§ DateTimeAPIs- JSR310
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
DefaultmethodsCollection<Person> people = ...;
int highestWeight = people.stream()
...
interface Collection<T> { ...default Stream<T> stream() {
...}
}
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
StaticMethodsInInterfaces
• Previouslyitwasnotpossibletoincludestaticmethodsinaninterface• Staticmethods,bydefinition,arenotabstract– @FunctionalInterface canhavezeroormorestaticmethods
static <T> Predicate<T> isEqual(Object target) {return (null == target)
? Objects::isNull: object -> target.equals(object);
}
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
MethodReferences
list.replaceAll(s -> s.toUpperCase());
list.replaceAll(String::toUpperCase);
list.sort(Comparator.comparing(p -> p.getName()));
list.sort(Comparator.comparing(Person::getName));
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Summary
• Lambdasarefunctions• JavaSE8definesnewAPIsusingfunctionalinterfaces• Defaultmethods• Methodreferences
Lambdasmakecodereadmoreliketheproblemstatement.Theresultingcodeisclear,concise,andeasytomaintainandmodify.
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
ToolsforJavaSE8
• Quicklyconvertanonymousinnerclassestolambdas
LambdaExpressions
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
ToolsforJavaSE8
• Easilyconvertfromlambdastomethodreferences
MethodReferences
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
ToolsforJavaSE8
• SpecifyascopeforupgradingtoJava8– All/currentprojects– Specificpackage– Specificclass
• Runconverters• Visuallypreviewproposalsforrefactoring
RefactoringinBatchMode
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Abridged Content List
§ LambdaExpressions§ DefaultMethods§ MethodReferences§ DateTimeAPIs- JSR310
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JDK8JavaTimeFeatures– JSR310
• Replacesjava.util.Date,Calendar,TimeZone,DateFormat• Fluent,Immutable,ThreadSafe,Easytouse• Strongtypingwithfitforpurposetypes• Easytouseformattingandparsing• Interoperablewithjava.util.Calendar/Date• ExtensibleUnits,Fields,andChronologies• SupportsRegionalCalendars• SupportedbyJDBC,java.sql.Date/Time/Timestamp• TheessentialISO8601Calendarforglobalbusiness
NewImprovedDateTimeAPI
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Rangeoftypesl Dateconsistsofyear,monthanddayl Time-of-dayconsistsofhour,minute,second
- LocalDate - adatewithnotimeandnotime-zone- LocalTime - atimewithnodateandnotime-zone- LocalDateTime - combinesLocalDateandLocalTime
l Time-zoneshandledseparately- ZonedDateTime - closestclasstojava.util.Calendar
l Instantaneouspointsintime- Instant - closestclasstojava.util.Date
InJDK8,youhavetochoosethecorrectdate/timetype
whendesigninganapplication!
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
LocalDatel Storesyear-month-day
- 12th March2017
l Usecases:birthdays,start/enddates,holidaydates
LocalDate current = LocalDate.now();LocalDate date = LocalDate.of(2013,Month.SEPTEMBER,12);if (current.isAfter(date)) …
String str = date.toString(); // 2013-09-12
boolean leap = date.isLeapYear();int monthLen = date.lengthOfMonth();
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
LocalTimel Storeshour-minute-second-nanosecond
- 13:30(1:30pm)
l Usecases:shopopeninghours,alarmclock
LocalTime current = LocalTime.now();LocalTime time = LocalTime.of(13,30);if (current.isAfter(time)) …
String str = time.toString(); // 13:30
time = time.plusHours(4).minusMinutes(1).withNano(0);time = time.truncatedTo(ChronoUnit.SECONDS);
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
LocalDate-Timel StoresLocalDate andLocalTime
- 12th September2013at13:30
l Usecase:localdate-timeaflighttakesoff
dt1 = LocalDateTime.now();dt2 = LocalDateTime.of(2013,SEPTEMBER,12, 13,30);
dt1 = dt1.plusDays(2).minusHours(1);dt1 = dt1.with(next(TUESDAY));
dt2.toString(); // 2013-09-12T13:30
dt2 = dt2.truncatedTo(MINUTES);
http://www.flickr.com/photos/estevesm/473866656/
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Instantl Storesnanosecondsfrom1970-01-01Zl Closestequivalenttojava.util.Datel Usecase:timestampinlogging
instant1 = Instant.now();instant2 = Instant.now();
if (instant1.isAfter(instant2)) { … }
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Timezonesl Worldisdividedintovarioustimezonesl Timeinalocationdefinedbypolitical rulesl Ruleschangefrequentlyandincomplexways
Ifyoucanavoidtime-zonesyourapplicationwillbesimpler!
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Timezonedesignl Fourclassesmanagetime-zonecomplexity
l ZoneId - "Europe/Paris",asperjava.util.TimeZonel ZoneOffset - "-05:00",offsetfromUTC/Greenwichl ZoneRules - behindthescenesclassdefiningtherulesl ZonedDateTime - maindate/timeclasswithtime-zones
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Calendarsystemsl Allmainclassesuse"ISO"calendarsysteml CalendarsystemdefinedinISO-8601
- current'civil'calendarappliedtoalltime- nothistoricallyaccurate
l Othercalendarsystemsalsosupported- notsupportedtothesamedegreeasISO- Hijrah,Japanese,Minguo,ThaiBuddhist intheJDK
l Onlyaffectdates,nottimes
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Durationl Time-basedamount
- hours,minutes,secondsandnanoseconds- somesupportfor24-hourdays
l Usecases:sportstopwatch,timeout
duration = Duration.ofHours(6); // PT6Hduration = duration.multipliedBy(3); // PT18Hduration = duration.plusMinutes(30); // PT18H30M
dt = LocalDateTime.now();dt = dt.plus(duration);
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Periodl Date-basedamount
- years,monthsanddays
l Usecases:lengthofpregnancy,lengthofholiday
period = Period.ofMonths(9); // P9Mperiod = period.plusDays(6); // P9M6D
dt = LocalDateTime.now();dt = dt.plus(period);
period = Period.between(startDate, endDate);
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Summaryl LocalDate 2016-12-03
l LocalTime 11:05:30
l LocalDateTime 2016-12-03T11:05:30
l ZonedDateTime 2016-12-03T11:05:30+01:00 Europe/Paris
l Instant 2576458258.266 seconds after 1970-01-01
l Duration PT30S (30 seconds)
l Period P1Y6M (1 year and 6 months)
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JDK8Innovation• LambdaakaClosures• LanguageInterop• Nashorn
CoreLibraries• Paralleloperationsforcore
collectionsAPIs• Improvementsinfunctionality• Improvedtypeinference
GeneralGoodness• JVMenhancements• NoPermGen limitations• Performanceimprovements
JavaforEveryone• Profilesforconstraineddevices• JSR310-Date&TimeAPIs• Non-Gregoriancalendars• Unicode6.2• ResourceBundle• BCP47localematching• Globalization&Accessibility
Tools• JSR308-AnnotationsonJavaType• Nativeappbundling• AppStoreBundlingtools• jdeps
Client• Deploymentenhancements• JavaFX8• PublicUIControlAPI• JavaSEEmbeddedsupport• EnhancedHTML5support• 3Dshapesandattributes• Printing
Security• LimiteddoPrivilege• NSASuiteBalgorithmsupport• SNIServerSidesupport• DSAupdatedtoFIPS186-3• AEADJSSECipherSuites
Enterprise• MissionControl• FlightRecorder• UsageTracker• AdvancedManagementConsole• MSIEnterpriseJREInstaller
38
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Wheredidmostofthisinformationcomefrom
• JavaSE8—LanguageandLibraryFeatures,BrianGoetz• IntroductiontoLambdaExpressions,StuartMarks• ANewDateandTimeAPI—JSR-310,StephenColebourne
Java8LaunchEvent
https://www.oracle.com/java8launch
Searchfor:Java 8 Launch
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
CominginJDK9
40
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Agenda
• Behindthescenesimprovements• Newfeaturesandfunctionality• Adoptingnewstandards• Housekeeping• Gone,gone,gone!
MoreinformationonanyJEP:http://openjdk.java.net/jeps/{JEP#}
Searchfor:OpenJDK 9
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
BehindthescenesimprovementsGoodnessyougetforfreejustbyupdatingtoJDK9Noneedforusertochangeanythingtobenefitfromthese
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP250:StoreInternedStringsinCDSArchives
• Storeinternedstringsinclass-datasharing(CDS)archives
• ReducememoryconsumptionbysharingtheStringobjectsandunderlyingchararrayobjectsamongstdifferentJVMprocesses• OnlysupportsharedstringsfortheG1GC.Sharedstringsrequireapinnedregion,andG1istheonlyHotSpot GCthatsupportspinning• Onlysupport64-bitplatformswithcompressedobjectandclasspointers
hotspot / runtime
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP254:CompactStrings
• Adoptamorespace-efficientinternalrepresentationforstrings
• Lessmemoryusedforstoringstrings• Stringclassstorescharactersinachararray,usingtwobytes(sixteenbits)foreachcharacter• ChangetheinternalrepresentationoftheStringclasstoabytearrayplusanencoding-flagfield
core-libs / java.lang
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP225:JavadocSearch
• AddasearchboxtogeneratedAPIdocumentationthatcanbeusedtosearchforprogramelementsandtaggedwordsandphraseswithinthedocumentation
tools / javadoc(tool)
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
NewfeaturesandfunctionalityNewtoolsandcapabilitieslikelytobeusefultomostdevelopersWillhavetochoosetousethese
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
ProjectJigsaw
• JEP261:ModuleSystem• JEP200:TheModularJDK• JEP201:ModularSourceCode• JEP220:ModularRun-TimeImages• Plus– JEP260:EncapsulateMostInternalAPIs– JEP282:jlink:TheJavaLinker
ModularizetheJavaPlatform
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP282:jlink:TheJavaLinker
• Createatoolthatcanassembleandoptimizeasetofmodulesandtheirdependenciesintoacustomrun-timeimageasdefinedinJEP220.Defineapluginmechanismfortransformationandoptimizationduringtheassemblyprocess,andforthegenerationofalternativeimageformats• Createacustomruntimeoptimizedforasingleprogram• JEP261defineslinktime asanoptionalphasebetweenthephasesofcompiletimeandruntime.Linktimerequiresalinkingtoolthatwillassembleandoptimizeasetofmodulesandtheirtransitivedependenciestocreatearun-timeimageorexecutable
tools / jlink
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP277:EnhancedDeprecation
• Revampthedeprecationannotation,andprovidetoolstostrengthentheAPIlifecycle• ProvidebetterinformationaboutthestatusandintendeddispositionofAPIsinthespecification• Provideatooltoanalyzeanapplication'sstaticusageofdeprecatedAPIs• Provideatooltodetectanapplication'sdynamicusageofofdeprecatedAPIsinordertoemitwarningsatruntime
core-libs / java.lang
@Deprecated(since=9,condemned=true)
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP269:ConvenienceFactoryMethodsforCollections
• DefinelibraryAPIstomakeitconvenienttocreateinstancesofcollectionsandmapswithsmallnumbersofelements,soastoeasethepainofnothavingcollectionliteralsintheJavaprogramminglanguage
• Decreasetheamountofcodeneededforcreatingsmallcollectionsandmaps
core-libs / java.util:collections
Set<String> alphabet = Set.of("a", "b", "c");
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP222:jshell:TheJavaShell(Read-Eval-PrintLoop)
• Provideaninteractivetooltoevaluatedeclarations,statements,andexpressionsoftheJavaprogramminglanguage,togetherwithanAPIsothatotherapplicationscanleveragethisfunctionality• ARead-Eval-PrintLoop(REPL)isaninteractiveprogrammingtoolwhichloops,continuallyreadinguserinput,evaluatingtheinput,andprintingthevalueoftheinputoradescriptionofthestatechangetheinputcaused.Scala,Ruby,JavaScript,Haskell,Clojure,andPythonallhaveREPLsandallallowsmallinitialprograms.JShell addsREPLfunctionalitytotheJavaplatform
tools / jshell
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP238:Multi-ReleaseJARFiles
• ExtendtheJARfileformattoallowmultiple,Java-release-specificversionsofclassfilestocoexistinasinglearchive
• WriteJDK-version-specificvariantsofthesamecodeintoasinglejarfile
tools / jar
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
AdoptingnewstandardsJDK9keepingupwithimprovementsintheindustry
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP267:Unicode 8.0
• UpgradeexistingplatformAPIstosupportversion8.0oftheUnicodeStandard
core-libs / java.lang
Ahom
AnatolianHieroglyphs
HatranMultaniOldHungarianSuttonSignWriting
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP226:UTF-8PropertyFiles
• DefineameansforapplicationstospecifypropertyfilesencodedinUTF-8,andextendtheResourceBundle APItoloadthem• Theplatformhasaproperties-fileformatbasedonISO-8859-1andanescapemechanismforcharactersthatcannotberepresentedinthatencoding
core-libs / java.util:i18n
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP249:OCSPStaplingforTLS
• ImplementOCSPstaplingviatheTLSCertificateStatusRequestextensionandtheMultipleCertificateStatusRequestExtension• CertificatestatuscheckingusingOCSPtypicallyinvolvesanetworkrequestforeachcertificatebeingchecked.Becauseoftheadditionalnetworkrequests,enablingOCSPcheckingforTLSontheclientsidecanhaveasignificantimpactonperformance.• OCSPstaplingallowsthepresenterofacertificate,ratherthantheissuingCertificateAuthority(CA),tobeartheresourcecostofprovidingOCSPresponses
security-libs / javax.net.ssl
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP287:SHA-3HashAlgorithms
• ImplementtheSHA-3cryptographichashfunctions(BYTE-only)specifiedinNISTFIPS202
security-libs / java.security
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP224:HTML5Javadoc
• Enhancethejavadoc tooltoallowgeneratingHTML5markup.
tools / javadoc(tool)
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP110:HTTP/2Client
• DefineanewHTTPclientAPIthatimplementsHTTP/2andWebSocket,andcanreplacethelegacyHttpURLConnection API• ForJDK9thisAPIwillbeontheincubatormodules(JEP11)withthegoalofaddingthemtothestandardonalaterrelease.
core-libs / java.net
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
HousekeepingSettingupforfutureimprovementsandreducingcomplexity
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP260:EncapsulateMostInternalAPIs
• MakemostoftheJDK'sinternalAPIsinaccessiblebydefaultbutleaveafewcritical,widely-usedinternalAPIsaccessible,untilsupportedreplacementsexistforallormostoftheirfunctionality– InordertokeepcriticalAPIswithoutareplacementaccessiblebydefaultsun.miscandsun.reflect willnotbehiddenandafewAPIskept“public”• sun.misc.Unsafe• sun.misc.{Signal,SignalHandler}• sun.reflect.Reflection::getCallerClass• sun.reflect.ReflectionFactory
– AllotherAPIsinthesepackages(e.g.sun.misc.Base64)willberemoved
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP275:ModularJavaApplicationPackaging
• IntegratefeaturesfromProjectJigsawintotheJavaPackager,includingmoduleawarenessandcustomruntimecreation
• Leveragejlink inourpackagertocreatesmallerpackages
• ThepackagerwillonlycreateapplicationsthatusetheJDK9runtime.
deploy / packager
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP223:NewVersion-StringScheme
• RevisetheJDK'sversion-stringschemesothatitiseasiertodistinguishmajor,minor,andsecurity-updatereleases
• Alignwithcurrentindustrypractices,inparticularSemanticVersioning• ProvideasimpleAPIforversion-stringparsing,validation,andcomparison
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP295:Ahead-of-TimeCompilation
• CompileJavaclassestonativecodepriortolaunchingthevirtualmachine.• Improvethestart-uptimeofbothsmallandlargeJavaapplications,withatmostalimitedimpactonpeakperformance.• AOTcompilationisdonebyanewtool,jaotc• Fortheinitialrelease,theonlysupportedmoduleisjava.base.• AOTcompilationofanyotherJDKmodule,orofusercode,isexperimental
hotspot / compiler
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP280:Indify StringConcatenation
• ChangethestaticString-concatenationbytecodesequencegeneratedbyjavac touseinvokedynamic callstoJDKlibraryfunctions.ThiswillenablefutureoptimizationsofStringconcatenationwithoutrequiringfurtherchangestothebytecodeemittedbyjavac
tools / javac
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP271:UnifiedGCLogging
• Reimplement GCloggingusingtheunifiedJVMloggingframeworkintroducedinJEP158
hotspot / gc
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP248:MakeG1theDefaultGarbageCollector
• MakeG1thedefaultgarbagecollectoron32- and64-bitserverconfigurations
• LimitingGCpausetimesis,ingeneral,moreimportantthanmaximizingthroughput.Switchingtoalow-pausecollectorsuchasG1shouldprovideabetteroverallexperience,formostusers,thanathroughput-orientedcollectorsuchastheParallelGC,whichiscurrentlythedefault
hotspot / gc
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP213:MillingProjectCoin
• AddresstheroughedgesofthechangesincludedinProjectCoin/JSR334aspartofJDK7/JavaSE7
1. Allow@SafeVargsonprivateinstancemethods
2. Alloweffectively-finalvariablestobeusedasresourcesinthetry-with-resourcesstatement
3. Allowdiamondwithanonymousclassesiftheargumenttypeoftheinferredtypeisdenotable
4. Completetheremoval,beguninJavaSE8,ofunderscorefromthesetoflegalidentifiernames
5. Supportforprivateinterfacemethods
tools / javac
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP290:FilterIncomingSerializationData
• Allowincomingstreamsofobject-serializationdatatobefilteredinordertoimprovebothsecurityandrobustness
• Allowsdeveloperstolockoutsomeserializeddata
core-libs / java.io:serialization
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
JEP214:RemoveGCCombinationsDeprecatedinJDK8hotspot / gc
• JEP173deprecatedsomeGCcombinationswithJDK8.• UnsupportedanduntestedsinceJDK8• IncrementalCMS(iCMS)removed
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
GeneralRule:LookOutforUnrecognizedVMOptions• LaunchingJREwithunrecognizedVMoptionsfails.• UsingdeprecatedoptionsinJDK8triggerswarningmessages:
$java-XX:MaxPermSize=1G-versionJavaHotSpot(TM)64-BitServerVMwarning:ignoringoptionMaxPermSize;supportwasremovedin8.0
• Previouslydeprecatedoptions,removedinJDK9,willfailtostart.– PermgenerationwasremovedinJDK8(JEP122).– Expectmanyprogramstorunintothisproblem.
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
• StoreInternedStringsinCDSArchives• ImproveContendedLocking• CompactStrings• ImproveSecureApplicationPerformance• LeverageCPUInstructionsforGHASHandRSA• TieredAttributionforjavac• JavadocSearch• MarlinGraphicsRenderer• HiDPI GraphicsonWindowsandLinux• EnableGTK3onLinux• UpdateJavaFX/MediatoNewerVersionof
GStreamer
• EnhancedDeprecation• Stack-WalkingAPI• ConvenienceFactoryMethodsforCollections• PlatformLoggingAPIandService• jshell:TheJavaShell(Read-Eval-PrintLoop)• CompileforOlderPlatformVersions• Multi-ReleaseJARFiles• Platform-SpecificDesktopFeatures• TIFFImageI/O\• Multi-ResolutionImages
• ProcessAPIUpdates• VariableHandles• Spin-WaitHints• DynamicLinkingofLanguage-
DefinedObjectModels• EnhancedMethodHandles• MoreConcurrencyUpdates• CompilerControl
• Jigsaw– ModularizeJDK
Behindthescenes
Newfunctionality
Specialized
• ParserAPIforNashorn• PrepareJavaFXUIControls&CSSAPIsfor
Modularization• ModularJavaApplicationPackaging• NewVersion-StringScheme• ReservedStackAreasforCriticalSections• SegmentedCodeCache• Ahead-of-TimeCompilation• Indify StringConcatenation• UnifiedJVMLogging• UnifiedGCLogging• MakeG1theDefaultGarbageCollector• UseCLDRLocaleDatabyDefault• ValidateJVMCommand-LineFlagArguments• Java-LevelJVMCompilerInterface• DisableSHA-1Certificates• SimplifiedDoclet API• DeprecatetheAppletAPI• ProcessImportStatementsCorrectly• AnnotationsPipeline2.0• ElideDeprecationWarningsonImport
Statements• MillingProjectCoin• FilterIncomingSerializationData• RemoveGCCombinationsDeprecatedin
JDK8• RemoveLaunch-TimeJREVersionSelection• RemovetheJVMTIhprof Agent• Removethejhat Tool
Housekeeping
Gone
• HTTP2Client• Unicode8.0• UTF-8PropertyFiles• ImplementSelectedECMAScript6
FeaturesinNashorn• DatagramTransportLayerSecurity
(DTLS)• OCSPStaplingforTLS• TLSApplication-LayerProtocol
NegotiationExtension• SHA-3HashAlgorithms• DRBG-BasedSecureRandom
Implementations• CreatePKCS12Keystores byDefault• MergeSelectedXerces2.11.0Updates
intoJAXP• XMLCatalogs• HarfBuzz Font-LayoutEngine• HTML5Javadoc
Newstandards
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
DownloadJDK9EA• EarlyaccessbuildsofJDK9
availablefortesting:– https://jdk9.java.net/download/
• Thereareperiodicupdates,socheckfrequentlyfornewerbuilds.
– See“Summaryofchanges”oneachbuild.
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Jointheconversation• ThereareOpenJDKaliasesforall
questions• http://mail.openjdk.java.net/mailman/listinfo
• EveryJEPlistsitsalias• Lookfor“Discussion”
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
DownloadNetBeansDev• EarlyaccessofNetBeanswith
supportforJDK9availableat:– http://wiki.netbeans.org/JDK9Support
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
IdentifyProblematicDependencies
• AvailablesinceJDK8,BestresultsfromtheversioninJDK9EA• Optiontofindinternaldependencies
UseJavaDependencyAnalysisTool(jdeps)
https://wiki.openjdk.java.net/display/JDK8/Java+Dependency+Analysis+Tool
tzupdater-2.0.3-2015b $ jdeps tzupdater.jartzupdater.jar -> java.base
com.sun.tools.tzupdater -> com.sun.tools.tzupdater.utils tzupdater.jar(...)
com.sun.tools.tzupdater -> java.util.regex java.basecom.sun.tools.tzupdater -> java.util.zip java.basecom.sun.tools.tzupdater -> sun.util.calendar JDK internal API (java.base)com.sun.tools.tzupdater -> tools.javazic tzupdater.jar
(...)com.sun.tools.tzupdater.utils -> java.util java.basecom.sun.tools.tzupdater.utils -> sun.util.calendar JDK internal API (java.base)tools.javazic -> java.io java.base
(...)
Copyright©2017, Oracleand/oritsaffiliates.Allrightsreserved.
Stopgap:ExposeInternalAPIs
• SamplecommandforearlierdevversionofNetbeans
Butcomebackandfix!
$bin/netbeans --jdkhome ~/jdk9ea--add-exportsjava.desktop/sun.awt=ALL-UNNAMED--add-exportsjava.base/jdk.internal.jrtfs=ALL-UNNAMED--add-exportsjava.desktop/java.awt.peer=ALL-UNNAMED--add-exportsjava.desktop/com.sun.beans.editors=ALL-UNNAMED--add-exportsjava.desktop/sun.awt.im=ALL-UNNAMED--add-exportsjava.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED--add-exportsjava.management/sun.management=ALL-UNNAMED,