1 Star 0 Fork 75

kuen / openjdk-1.8.0

forked from src-openEuler / openjdk-1.8.0 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
add-appcds-test-case.patch 146.08 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720
diff --git a/hotspot/test/runtime/appcds/AppCDSOptions.java b/hotspot/test/runtime/appcds/AppCDSOptions.java
new file mode 100644
index 00000000..f5ebb5d5
--- /dev/null
+++ b/hotspot/test/runtime/appcds/AppCDSOptions.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+// This class represents options used for
+// during creation of the archive and/or running JVM with archive
+
+import com.oracle.java.testlibrary.cds.CDSOptions;
+
+public class AppCDSOptions extends CDSOptions {
+ public String appJar;
+
+ // Application classes to be archived
+ public String[] appClasses;
+
+ public AppCDSOptions setAppJar(String appJar) {
+ this.appJar = appJar;
+ return this;
+ }
+
+ public AppCDSOptions setAppClasses(String[] appClasses) {
+ this.appClasses = appClasses;
+ return this;
+ }
+
+}
diff --git a/hotspot/test/runtime/appcds/AppendClasspath.java b/hotspot/test/runtime/appcds/AppendClasspath.java
new file mode 100644
index 00000000..7ebe7f62
--- /dev/null
+++ b/hotspot/test/runtime/appcds/AppendClasspath.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary At run time, it is OK to append new elements to the classpath that was used at dump time.
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @compile test-classes/HelloMore.java
+ * @run main AppendClasspath
+ */
+
+import java.io.File;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class AppendClasspath {
+
+ public static void main(String[] args) throws Exception {
+ String appJar = JarBuilder.getOrCreateHelloJar();
+ System.out.println("appJar = ");
+ System.out.println(appJar);
+ String appJar2 = JarBuilder.build("AppendClasspath_HelloMore", "HelloMore");
+ System.out.println("appJar2 = ");
+ System.out.println(appJar2);
+ // Dump an archive with a specified JAR file in -classpath
+ TestCommon.testDump(appJar, TestCommon.list("Hello"));
+
+ // PASS: 1) runtime with classpath containing the one used in dump time
+ TestCommon.run(
+ "-cp", appJar + File.pathSeparator + appJar2,
+ "HelloMore")
+ .assertNormalExit();
+
+ // PASS: 2) runtime with classpath different from the one used in dump time
+ TestCommon.run(
+ "-cp", appJar2 + File.pathSeparator + appJar,
+ "HelloMore");
+
+ // PASS: 3) runtime with classpath part of the one used in dump time
+ TestCommon.testDump(appJar + File.pathSeparator + appJar2,
+ TestCommon.list("Hello"));
+ TestCommon.run(
+ "-cp", appJar2,
+ "Hello");
+
+ // PASS: 4) runtime with same set of jar files in the classpath but
+ // with different order
+ TestCommon.run(
+ "-cp", appJar2 + File.pathSeparator + appJar,
+ "HelloMore");
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/CaseSensitiveClassPath.java b/hotspot/test/runtime/appcds/CaseSensitiveClassPath.java
new file mode 100644
index 00000000..689d2a17
--- /dev/null
+++ b/hotspot/test/runtime/appcds/CaseSensitiveClassPath.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+
+/*
+ * @test
+ * @summary Test case sensitive aspect of comparing class paths
+ * between dump time and archive use time
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main CaseSensitiveClassPath
+ */
+
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import com.oracle.java.testlibrary.Platform;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+
+// Excluded from running on MAC: a more comprehensive case sensitivity detection
+// and fix mechanism is needed, which is planned to be implemented in the future.
+public class CaseSensitiveClassPath {
+ public static void main(String[] args) throws Exception {
+ String appJar = JarBuilder.getOrCreateHelloJar();
+ String appJarUpper = appJar.replace("hello", "Hello");
+
+ OutputAnalyzer out = TestCommon.dump(appJar, TestCommon.list("Hello"));
+ TestCommon.checkDump(out);
+
+ Path jarPath = Paths.get(appJar);
+ Path jarPathUpper = null;
+
+ boolean fileExists = false;
+ try {
+ jarPathUpper = Files.createFile(Paths.get(appJarUpper));
+ } catch (FileAlreadyExistsException faee) {
+ fileExists = true;
+ }
+
+ if (!fileExists) {
+ try {
+ Files.copy(jarPath, jarPathUpper, StandardCopyOption.REPLACE_EXISTING);
+ } catch (Exception e) {
+ throw new java.lang.RuntimeException(
+ "Failed copying file from " + appJar + " to " + appJarUpper + ".", e);
+ }
+ } else {
+ jarPathUpper = Paths.get(appJarUpper);
+ }
+ boolean isSameFile = Files.isSameFile(jarPath, jarPathUpper);
+
+ TestCommon.run("-cp", appJarUpper, "Hello", "-Xlog:class+path=info",
+ "-Xlog:cds")
+ .ifNoMappingFailure(output -> {
+ output.shouldContain("Hello World");
+ });
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/CommandLineFlagCombo.java b/hotspot/test/runtime/appcds/CommandLineFlagCombo.java
new file mode 100644
index 00000000..7f7ca7bf
--- /dev/null
+++ b/hotspot/test/runtime/appcds/CommandLineFlagCombo.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test CommandLineFlagCombo
+ * @requires (vm.gc=="null")
+ * @summary Test command line flag combinations that
+ * could likely affect the behaviour of AppCDS
+ * @library /testlibrary /testlibrary/whitebox
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @compile test-classes/Hello.java
+ * @run main/othervm/timeout=240 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CommandLineFlagCombo
+ */
+
+import com.oracle.java.testlibrary.BuildHelper;
+import com.oracle.java.testlibrary.Platform;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+import sun.hotspot.code.Compiler;
+
+public class CommandLineFlagCombo {
+
+ // shared base address test table
+ private static final String[] testTable = {
+ "-XX:+UseG1GC", "-XX:+UseSerialGC", "-XX:+UseParallelGC", "-XX:+UseConcMarkSweepGC",
+ "-XX:+FlightRecorder",
+ "-XX:+UseLargePages", // may only take effect on machines with large-pages
+ "-XX:+UseCompressedClassPointers",
+ "-XX:+UseCompressedOops",
+ "-XX:ObjectAlignmentInBytes=16",
+ "-XX:ObjectAlignmentInBytes=32",
+ "-XX:ObjectAlignmentInBytes=64"
+ };
+
+ public static void main(String[] args) throws Exception {
+ String appJar = JarBuilder.getOrCreateHelloJar();
+ String classList[] = {"Hello"};
+
+ for (String testEntry : testTable) {
+ System.out.println("CommandLineFlagCombo = " + testEntry);
+
+ if (skipTestCase(testEntry))
+ continue;
+
+ OutputAnalyzer dumpOutput = TestCommon.dump(appJar, classList, testEntry);
+ TestCommon.checkDump(dumpOutput, "Loading classes to share");
+
+ OutputAnalyzer execOutput = TestCommon.exec(appJar, testEntry, "Hello");
+ TestCommon.checkExec(execOutput, "Hello World");
+ }
+
+ for (int i=0; i<2; i++) {
+ String g1Flag, serialFlag;
+
+ // Interned strings are supported only with G1GC. However, we should not crash if:
+ // 0: archive has shared strings, but run time doesn't support shared strings
+ // 1: archive has no shared strings, but run time supports shared strings
+
+ String dump_g1Flag = "-XX:" + (i == 0 ? "+" : "-") + "UseG1GC";
+ String run_g1Flag = "-XX:" + (i != 0 ? "+" : "-") + "UseG1GC";
+ String dump_serialFlag = "-XX:" + (i != 0 ? "+" : "-") + "UseSerialGC";
+ String run_serialFlag = "-XX:" + (i == 0 ? "+" : "-") + "UseSerialGC";
+
+ OutputAnalyzer dumpOutput = TestCommon.dump(
+ appJar, classList, dump_g1Flag, dump_serialFlag);
+
+ TestCommon.checkDump(dumpOutput, "Loading classes to share");
+
+ OutputAnalyzer execOutput = TestCommon.exec(appJar, run_g1Flag, run_serialFlag, "Hello");
+ TestCommon.checkExec(execOutput, "Hello World");
+ }
+ }
+
+ private static boolean skipTestCase(String testEntry) throws Exception {
+ if (Platform.is32bit())
+ {
+ if (testEntry.equals("-XX:+UseCompressedOops") ||
+ testEntry.equals("-XX:+UseCompressedClassPointers") ||
+ testEntry.contains("ObjectAlignmentInBytes") )
+ {
+ System.out.println("Test case not applicable on 32-bit platforms");
+ return true;
+ }
+ }
+
+ if (Compiler.isGraalEnabled() && testEntry.equals("-XX:+UseConcMarkSweepGC"))
+ {
+ System.out.println("Graal does not support CMS");
+ return true;
+ }
+
+ return false;
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/CommandLineFlagComboNegative.java b/hotspot/test/runtime/appcds/CommandLineFlagComboNegative.java
new file mode 100644
index 00000000..4fb965ab
--- /dev/null
+++ b/hotspot/test/runtime/appcds/CommandLineFlagComboNegative.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test CommandLineFlagComboNegative
+ * @summary Test command line flag combinations that differ between
+ * the dump and execute steps, in such way that they cause errors
+ * E.g. use compressed oops for creating and archive, but then
+ * execute w/o compressed oops
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main CommandLineFlagComboNegative
+ */
+
+import java.util.ArrayList;
+import com.oracle.java.testlibrary.Platform;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class CommandLineFlagComboNegative {
+
+ private class TestVector {
+ public String testOptionForDumpStep;
+ public String testOptionForExecuteStep;
+ public String expectedErrorMsg;
+ public int expectedErrorCode;
+
+ public TestVector(String testOptionForDumpStep, String testOptionForExecuteStep,
+ String expectedErrorMsg, int expectedErrorCode) {
+ this.testOptionForDumpStep=testOptionForDumpStep;
+ this.testOptionForExecuteStep=testOptionForExecuteStep;
+ this.expectedErrorMsg=expectedErrorMsg;
+ this.expectedErrorCode=expectedErrorCode;
+ }
+ }
+
+ private ArrayList<TestVector> testTable = new ArrayList<TestVector>();
+
+ private void initTestTable() {
+ // These options are not applicable on 32-bit platforms
+ if (Platform.is64bit()) {
+ testTable.add( new TestVector("-XX:ObjectAlignmentInBytes=8", "-XX:ObjectAlignmentInBytes=16",
+ "An error has occurred while processing the shared archive file", 1) );
+ testTable.add( new TestVector("-XX:ObjectAlignmentInBytes=64", "-XX:ObjectAlignmentInBytes=32",
+ "An error has occurred while processing the shared archive file", 1) );
+ testTable.add( new TestVector("-XX:+UseCompressedOops", "-XX:-UseCompressedOops",
+ "Class data sharing is inconsistent with other specified options", 1) );
+ testTable.add( new TestVector("-XX:+UseCompressedClassPointers", "-XX:-UseCompressedClassPointers",
+ "Class data sharing is inconsistent with other specified options", 1) );
+ }
+ }
+
+ private void runTests() throws Exception
+ {
+ for (TestVector testEntry : testTable) {
+ System.out.println("CommandLineFlagComboNegative: dump = " + testEntry.testOptionForDumpStep);
+ System.out.println("CommandLineFlagComboNegative: execute = " + testEntry.testOptionForExecuteStep);
+
+ String appJar = JarBuilder.getOrCreateHelloJar();
+ OutputAnalyzer dumpOutput = TestCommon.dump(
+ appJar, new String[] {"Hello"}, testEntry.testOptionForDumpStep);
+
+ TestCommon.checkDump(dumpOutput, "Loading classes to share");
+
+ TestCommon.run(
+ "-cp", appJar,
+ testEntry.testOptionForExecuteStep,
+ "Hello")
+ .assertAbnormalExit(output -> {
+ output.shouldContain(testEntry.expectedErrorMsg)
+ .shouldHaveExitValue(testEntry.expectedErrorCode);
+ });
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ CommandLineFlagComboNegative thisClass = new CommandLineFlagComboNegative();
+ thisClass.initTestTable();
+ thisClass.runTests();
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/DirClasspathTest.java b/hotspot/test/runtime/appcds/DirClasspathTest.java
new file mode 100644
index 00000000..e2c4e698
--- /dev/null
+++ b/hotspot/test/runtime/appcds/DirClasspathTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Handling of directories in -cp is based on the classlist
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main DirClasspathTest
+ */
+
+import com.oracle.java.testlibrary.Platform;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+
+public class DirClasspathTest {
+ private static final int MAX_PATH = 260;
+
+ public static void main(String[] args) throws Exception {
+ File dir = new File(System.getProperty("user.dir"));
+ File emptydir = new File(dir, "emptydir");
+ emptydir.mkdir();
+
+ /////////////////////////////////////////////////////////////////
+ // The classlist only contains boot class in following test cases
+ /////////////////////////////////////////////////////////////////
+ String bootClassList[] = {"java/lang/Object"};
+
+ // Empty dir in -cp: should be OK
+ OutputAnalyzer output;
+ output = TestCommon.dump(emptydir.getPath(), bootClassList);
+ TestCommon.checkDump(output);
+
+ // Long path to empty dir in -cp: should be OK
+ Path classDir = Paths.get(System.getProperty("test.classes"));
+ Path destDir = classDir;
+ int subDirLen = MAX_PATH - classDir.toString().length() - 2;
+ if (subDirLen > 0) {
+ char[] chars = new char[subDirLen];
+ Arrays.fill(chars, 'x');
+ String subPath = new String(chars);
+ destDir = Paths.get(System.getProperty("test.classes"), subPath);
+ }
+ File longDir = destDir.toFile();
+ longDir.mkdir();
+ File subDir = new File(longDir, "subdir");
+ subDir.mkdir();
+ output = TestCommon.dump(subDir.getPath(), bootClassList);
+ TestCommon.checkDump(output);
+
+ // Non-empty dir in -cp: should be OK
+ // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
+ output = TestCommon.dump(dir.getPath(), bootClassList);
+ TestCommon.checkDump(output);
+
+ // Long path to non-empty dir in -cp: should be OK
+ // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir>
+ output = TestCommon.dump(longDir.getPath(), bootClassList);
+ TestCommon.checkDump(output);
+
+ /////////////////////////////////////////////////////////////////
+ // The classlist contains non-boot class in following test cases
+ /////////////////////////////////////////////////////////////////
+ String appClassList[] = {"java/lang/Object", "com/sun/tools/javac/Main"};
+
+ // Non-empty dir in -cp: should be OK (as long as no classes were loaded from there)
+ output = TestCommon.dump(dir.getPath(), appClassList);
+ TestCommon.checkDump(output);
+
+ // Long path to non-empty dir in -cp: should be OK (as long as no classes were loaded from there)
+ output = TestCommon.dump(longDir.getPath(), appClassList);
+ TestCommon.checkDump(output);
+
+ /////////////////////////////////////////////////////////////////
+ // Loading an app class from a directory
+ /////////////////////////////////////////////////////////////////
+ String appClassList2[] = {"Hello", "java/lang/Object", "com/sun/tools/javac/Main"};
+ // Non-empty dir in -cp: should report error if a class is loaded from it
+ output = TestCommon.dump(classDir.toString(), appClassList2);
+ output.shouldNotHaveExitValue(1);
+ output.shouldContain("Cannot find com/sun/tools/javac/Main");
+ // Long path to non-empty dir in -cp: should report error if a class is loaded from it
+ File srcClass = new File(classDir.toFile(), "Hello.class");
+ File destClass = new File(longDir, "Hello.class");
+ Files.copy(srcClass.toPath(), destClass.toPath());
+ output = TestCommon.dump(longDir.getPath(), appClassList2);
+ output.shouldNotHaveExitValue(1);
+ output.shouldContain("Cannot find Hello");
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/HelloTest.java b/hotspot/test/runtime/appcds/HelloTest.java
new file mode 100644
index 00000000..c49179a1
--- /dev/null
+++ b/hotspot/test/runtime/appcds/HelloTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Hello World test for AppCDS
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main HelloTest
+ */
+
+public class HelloTest {
+ public static void main(String[] args) throws Exception {
+ TestCommon.test(JarBuilder.getOrCreateHelloJar(),
+ TestCommon.list("Hello"), "Hello");
+ }
+}
diff --git a/hotspot/test/runtime/appcds/IgnoreEmptyClassPaths.java b/hotspot/test/runtime/appcds/IgnoreEmptyClassPaths.java
new file mode 100644
index 00000000..36618b17
--- /dev/null
+++ b/hotspot/test/runtime/appcds/IgnoreEmptyClassPaths.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Test the -XX:+IgnoreEmptyClassPaths flag
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @compile test-classes/HelloMore.java
+ * @run main IgnoreEmptyClassPaths
+ */
+
+import java.io.File;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class IgnoreEmptyClassPaths {
+
+ public static void main(String[] args) throws Exception {
+ String jar1 = JarBuilder.getOrCreateHelloJar();
+ String jar2 = JarBuilder.build("IgnoreEmptyClassPaths_more", "HelloMore");
+
+ String sep = File.pathSeparator;
+ String cp_dump = jar1 + sep + jar2 + sep;
+ String cp_exec = sep + jar1 + sep + sep + jar2 + sep;
+
+ TestCommon.testDump(cp_dump, TestCommon.list("Hello", "HelloMore"),
+ "-XX:+TraceClassPaths", "-XX:+IgnoreEmptyClassPaths");
+
+ TestCommon.run(
+ "-verbose:class",
+ "-cp", cp_exec,
+ "-XX:+IgnoreEmptyClassPaths", // should affect classpath even if placed after the "-cp" argument
+ "-XX:+TraceClassPaths",
+ "HelloMore")
+ .assertNormalExit();
+ }
+}
diff --git a/hotspot/test/runtime/appcds/JarBuilder.java b/hotspot/test/runtime/appcds/JarBuilder.java
new file mode 100644
index 00000000..e06ab2bc
--- /dev/null
+++ b/hotspot/test/runtime/appcds/JarBuilder.java
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @summary Simple jar builder
+ * Input: jarName className1 className2 ...
+ * do not specify extensions, just the names
+ * E.g. prot_domain ProtDomainA ProtDomainB
+ * Output: A jar containing compiled classes, placed in a test classes folder
+ * @library /open/test/lib
+ */
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.ArrayList;
+
+import com.oracle.java.testlibrary.JDKToolFinder;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.compiler.CompilerUtils;
+import sun.tools.jar.Main;
+
+public class JarBuilder {
+ // to turn DEBUG on via command line: -DJarBuilder.DEBUG=[true, TRUE]
+ private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("JarBuilder.DEBUG", "false"));
+ private static final String classDir = System.getProperty("test.classes");
+
+ public static String getJarFilePath(String jarName) {
+ return classDir + File.separator + jarName + ".jar";
+ }
+
+ // jar all files under dir, with manifest file man, with an optional versionArgs
+ // for generating a multi-release jar.
+ // The jar command is as follows:
+ // jar cmf \
+ // <path to output jar> <path to the manifest file>\
+ // -C <path to the base classes> .\
+ // --release 9 -C <path to the versioned classes> .
+ // the last line begins with "--release" corresponds to the optional versionArgs.
+ public static void build(String jarName, File dir, String man, String...versionArgs)
+ throws Exception {
+ ArrayList<String> args = new ArrayList<String>();
+ if (man != null) {
+ args.add("cfm");
+ } else {
+ args.add("cf");
+ }
+ args.add(classDir + File.separator + jarName + ".jar");
+ if (man != null) {
+ args.add(man);
+ }
+ args.add("-C");
+ args.add(dir.getAbsolutePath());
+ args.add(".");
+ for (String verArg : versionArgs) {
+ args.add(verArg);
+ }
+ createJar(args);
+ }
+
+ public static String build(String jarName, String...classNames)
+ throws Exception {
+
+ return createSimpleJar(classDir, getJarFilePath(jarName), classNames);
+ }
+
+ public static String build(boolean classesInWorkDir, String jarName, String...classNames)
+ throws Exception {
+ if (classesInWorkDir) {
+ return createSimpleJar(".", getJarFilePath(jarName), classNames);
+ } else {
+ return build(jarName, classNames);
+ }
+ }
+
+
+ public static String buildWithManifest(String jarName, String manifest,
+ String jarClassesDir, String...classNames) throws Exception {
+ String jarPath = getJarFilePath(jarName);
+ ArrayList<String> args = new ArrayList<String>();
+ args.add("cvfm");
+ args.add(jarPath);
+ args.add(System.getProperty("test.src") + File.separator + "test-classes"
+ + File.separator + manifest);
+ addClassArgs(args, jarClassesDir, classNames);
+ createJar(args);
+
+ return jarPath;
+ }
+
+
+ // Execute: jar uvf $jarFile -C $dir .
+ static void update(String jarFile, String dir) throws Exception {
+ String jarExe = JDKToolFinder.getJDKTool("jar");
+
+ ArrayList<String> args = new ArrayList<>();
+ args.add(jarExe);
+ args.add("uvf");
+ args.add(jarFile);
+ args.add("-C");
+ args.add(dir);
+ args.add(".");
+
+ executeProcess(args.toArray(new String[1]));
+ }
+
+
+ private static String createSimpleJar(String jarclassDir, String jarName,
+ String[] classNames) throws Exception {
+
+ ArrayList<String> args = new ArrayList<String>();
+ args.add("cf");
+ args.add(jarName);
+ addClassArgs(args, jarclassDir, classNames);
+ createJar(args);
+
+ return jarName;
+ }
+
+ private static void addClassArgs(ArrayList<String> args, String jarclassDir,
+ String[] classNames) {
+
+ for (String name : classNames) {
+ args.add("-C");
+ args.add(jarclassDir);
+ args.add(name + ".class");
+ }
+ }
+
+ public static void createModularJar(String jarPath,
+ String classesDir,
+ String mainClass) throws Exception {
+ ArrayList<String> argList = new ArrayList<String>();
+ argList.add("--create");
+ argList.add("--file=" + jarPath);
+ if (mainClass != null) {
+ argList.add("--main-class=" + mainClass);
+ }
+ argList.add("-C");
+ argList.add(classesDir);
+ argList.add(".");
+ createJar(argList);
+ }
+
+ private static void createJar(ArrayList<String> args) {
+ if (DEBUG) printIterable("createJar args: ", args);
+
+ Main jarTool = new Main(System.out, System.err, "jar");
+ if (!jarTool.run(args.toArray(new String[1]))) {
+ throw new RuntimeException("jar operation failed");
+ }
+ }
+
+ // Many AppCDS tests use the same simple "Hello.jar" which contains
+ // simple Hello.class and does not specify additional attributes.
+ // For this common use case, use this method to get the jar path.
+ // The method will check if the jar already exists
+ // (created by another test or test run), and will create the jar
+ // if it does not exist
+ public static String getOrCreateHelloJar() throws Exception {
+ String jarPath = getJarFilePath("hello");
+
+ File jarFile = new File(jarPath);
+ if (jarFile.exists()) {
+ return jarPath;
+ } else {
+ return build("hello", "Hello");
+ }
+ }
+
+ public static void compile(String dstPath, String source, String... extraArgs) throws Exception {
+ ArrayList<String> args = new ArrayList<String>();
+ args.add(JDKToolFinder.getCompileJDKTool("javac"));
+ args.add("-d");
+ args.add(dstPath);
+ if (extraArgs != null) {
+ for (String s : extraArgs) {
+ args.add(s);
+ }
+ }
+ args.add(source);
+
+ if (DEBUG) printIterable("compile args: ", args);
+
+ ProcessBuilder pb = new ProcessBuilder(args);
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+ output.shouldHaveExitValue(0);
+ }
+
+ public static void compileModule(Path src,
+ Path dest,
+ String modulePathArg // arg to --module-path
+ ) throws Exception {
+ boolean compiled = false;
+ if (modulePathArg == null) {
+ compiled = CompilerUtils.compile(src, dest);
+ } else {
+ compiled = CompilerUtils.compile(src, dest,
+ "--module-path", modulePathArg);
+ }
+ if (!compiled) {
+ throw new RuntimeException("module did not compile");
+ }
+ }
+
+
+ public static void signJar() throws Exception {
+ String keyTool = JDKToolFinder.getJDKTool("keytool");
+ String jarSigner = JDKToolFinder.getJDKTool("jarsigner");
+ String classDir = System.getProperty("test.classes");
+ String FS = File.separator;
+
+ executeProcess(keyTool,
+ "-genkey", "-keystore", "./keystore", "-alias", "mykey",
+ "-storepass", "abc123", "-keypass", "abc123",
+ "-dname", "CN=jvmtest")
+ .shouldHaveExitValue(0);
+
+ executeProcess(jarSigner,
+ "-keystore", "./keystore", "-storepass", "abc123", "-keypass",
+ "abc123", "-signedjar", classDir + FS + "signed_hello.jar",
+ classDir + FS + "hello.jar", "mykey")
+ .shouldHaveExitValue(0);
+ }
+
+ private static OutputAnalyzer executeProcess(String... cmds)
+ throws Exception {
+
+ JarBuilder.printArray("executeProcess: ", cmds);
+ return ProcessTools.executeProcess(new ProcessBuilder(cmds));
+ }
+
+ // diagnostic
+ public static void printIterable(String msg, Iterable<String> l) {
+ StringBuilder sum = new StringBuilder();
+ for (String s : l) {
+ sum.append(s).append(' ');
+ }
+ System.out.println(msg + sum.toString());
+ }
+
+ public static void printArray(String msg, String[] l) {
+ StringBuilder sum = new StringBuilder();
+ for (String s : l) {
+ sum.append(s).append(' ');
+ }
+ System.out.println(msg + sum.toString());
+ }
+}
diff --git a/hotspot/test/runtime/appcds/MismatchedUseAppCDS.java b/hotspot/test/runtime/appcds/MismatchedUseAppCDS.java
new file mode 100644
index 00000000..7173d6c9
--- /dev/null
+++ b/hotspot/test/runtime/appcds/MismatchedUseAppCDS.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Try different combination of mismatched UseAppCDS between dump time and run time.
+ * @library /testlibrary /testlibrary/whitebox
+ * @compile test-classes/CheckIfShared.java
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main MismatchedUseAppCDS
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class MismatchedUseAppCDS {
+ public static void main(String[] args) throws Exception {
+ String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
+ String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
+
+ String appJar = JarBuilder.build("MismatchedUseAppCDS", "CheckIfShared");
+
+ OutputAnalyzer output;
+
+ // (1): dump with -XX:+UseAppCDS, but run with -XX:-UseAppCDS
+ TestCommon.testDump(appJar, TestCommon.list("CheckIfShared"),
+ // command-line arguments ...
+ "-XX:+UseAppCDS",
+ use_whitebox_jar);
+
+ output = TestCommon.exec(appJar,
+ // command-line arguments ...
+ use_whitebox_jar,
+ "-XX:+UnlockDiagnosticVMOptions",
+ "-XX:+WhiteBoxAPI",
+ "CheckIfShared", "false");
+ TestCommon.checkExec(output);
+
+ // (2): dump with -XX:-UseAppCDS, but run with -XX:+UseAppCDS
+ TestCommon.testDump(appJar, TestCommon.list("CheckIfShared"),
+ // command-line arguments ...
+ "-XX:+UseAppCDS",
+ use_whitebox_jar);
+
+ output = TestCommon.exec(appJar,
+ // command-line arguments ...
+ use_whitebox_jar,
+ "-XX:+UseAppCDS",
+ "-XX:+UnlockDiagnosticVMOptions",
+ "-XX:+WhiteBoxAPI",
+ "CheckIfShared", "true");
+ TestCommon.checkExec(output);
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/MissingSuperTest.java b/hotspot/test/runtime/appcds/MissingSuperTest.java
new file mode 100644
index 00000000..33a860b4
--- /dev/null
+++ b/hotspot/test/runtime/appcds/MissingSuperTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary When super class is missing during dumping, no crash should happen.
+ * @library /testlibrary
+ * @compile test-classes/MissingSuper.java
+ * @run main MissingSuperTest
+ */
+
+public class MissingSuperTest {
+
+ public static void main(String[] args) throws Exception {
+ // The classes "MissingSuperSup" and "MissingSuperIntf" are intentionally not
+ // included into the jar to provoke the test condition
+ JarBuilder.build("missing_super", "MissingSuper",
+ "MissingSuperSub", "MissingSuperImpl");
+
+ String appJar = TestCommon.getTestJar("missing_super.jar");
+ TestCommon.test(appJar, TestCommon.list("MissingSuper",
+ "MissingSuperSub",
+ "MissingSuperImpl"),
+ "MissingSuper");
+ }
+}
diff --git a/hotspot/test/runtime/appcds/PackageSealing.java b/hotspot/test/runtime/appcds/PackageSealing.java
new file mode 100644
index 00000000..6c915085
--- /dev/null
+++ b/hotspot/test/runtime/appcds/PackageSealing.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary AppCDS handling of package.
+ * @library /testlibrary
+ * @compile test-classes/C1.java
+ * @compile test-classes/C2.java
+ * @compile test-classes/PackageSealingTest.java
+ * @run main PackageSealing
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class PackageSealing {
+ public static void main(String args[]) throws Exception {
+ String[] classList = {"sealed/pkg/C1", "pkg/C2", "PackageSealingTest"};
+ String appJar = ClassFileInstaller.writeJar("pkg_seal.jar",
+ ClassFileInstaller.Manifest.fromSourceFile("test-classes/package_seal.mf"),
+ "PackageSealingTest", "sealed/pkg/C1", "pkg/C2");
+
+ // test shared package from -cp path
+ TestCommon.testDump(appJar, TestCommon.list(classList));
+ OutputAnalyzer output;
+ output = TestCommon.exec(appJar, "PackageSealingTest");
+ TestCommon.checkExec(output);
+
+ // test shared package from -Xbootclasspath/a
+ TestCommon.dump(appJar, TestCommon.list(classList),
+ "-Xbootclasspath/a:" + appJar);
+ output = TestCommon.exec(appJar, "-Xbootclasspath/a:" + appJar, "PackageSealingTest");
+ TestCommon.checkExec(output);
+ }
+}
diff --git a/hotspot/test/runtime/appcds/ParallelLoad2.java b/hotspot/test/runtime/appcds/ParallelLoad2.java
new file mode 100644
index 00000000..5709be6a
--- /dev/null
+++ b/hotspot/test/runtime/appcds/ParallelLoad2.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Load app classes from CDS archive in parallel threads. Similar to ParallelLoad.java, but each class in its own JAR
+ * @library /testlibrary
+ * @compile test-classes/ParallelLoad.java
+ * @compile test-classes/ParallelClasses.java
+ * @run main ParallelLoad2
+ */
+
+import java.io.File;
+
+public class ParallelLoad2 {
+ public static int MAX_CLASSES = 40;
+ public static void main(String[] args) throws Exception {
+ JarBuilder.build("parallel_load2", "ParallelLoad", "ParallelLoadThread", "ParallelLoadWatchdog");
+ for (int i=0; i<MAX_CLASSES; i++) {
+ JarBuilder.build("parallel_load2_" + i, "ParallelClass" + i);
+ }
+
+ String cp = TestCommon.getTestJar("parallel_load2.jar");
+ for (int i=0; i<MAX_CLASSES; i++) {
+ cp += File.pathSeparator + TestCommon.getTestJar("parallel_load2_" + i + ".jar");
+ }
+
+ String[] class_list = new String[MAX_CLASSES + 2];
+ for (int i=0; i<MAX_CLASSES; i++) {
+ class_list[i] = "ParallelClass" + i;
+ }
+ class_list[class_list.length - 1] = "ParallelLoad";
+ class_list[class_list.length - 2] = "ParallelLoadThread";
+
+ TestCommon.test(cp, class_list,
+ "ParallelLoad");
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/ParallelLoadTest.java b/hotspot/test/runtime/appcds/ParallelLoadTest.java
new file mode 100644
index 00000000..92d17a47
--- /dev/null
+++ b/hotspot/test/runtime/appcds/ParallelLoadTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Load app classes from CDS archive in parallel threads
+ * @library /testlibrary
+ * @compile test-classes/ParallelLoad.java
+ * @compile test-classes/ParallelClasses.java
+ * @run main ParallelLoadTest
+ */
+
+public class ParallelLoadTest {
+ public static final int MAX_CLASSES = 40;
+
+ public static void main(String[] args) throws Exception {
+ JarBuilder.build("parallel_load", getClassList(true));
+ String appJar = TestCommon.getTestJar("parallel_load.jar");
+ TestCommon.test(appJar, getClassList(false), "ParallelLoad");
+ }
+
+ private static String[] getClassList(boolean includeWatchdog) {
+ int extra = includeWatchdog ? 3 : 2;
+ String[] classList = new String[MAX_CLASSES + extra];
+
+ int i;
+ for (i=0; i<MAX_CLASSES; i++) {
+ classList[i] = "ParallelClass" + i;
+ }
+
+ classList[i++] = "ParallelLoad";
+ classList[i++] = "ParallelLoadThread";
+ if (includeWatchdog)
+ classList[i++] = "ParallelLoadWatchdog";
+
+ return classList;
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/SharedBaseAddress.java b/hotspot/test/runtime/appcds/SharedBaseAddress.java
new file mode 100644
index 00000000..b03b0876
--- /dev/null
+++ b/hotspot/test/runtime/appcds/SharedBaseAddress.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test SharedBaseAddress
+ * @summary Test variety of values for SharedBaseAddress, in AppCDS mode,
+ * making sure VM handles normal values as well as edge values
+ * w/o a crash.
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main/timeout=240 SharedBaseAddress
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class SharedBaseAddress {
+
+ // shared base address test table
+ private static final String[] testTable = {
+ "1g", "8g", "64g","512g", "4t",
+ "32t", "128t", "0",
+ "1", "64k", "64M"
+ };
+
+ public static void main(String[] args) throws Exception {
+ String appJar = JarBuilder.getOrCreateHelloJar();
+
+ for (String testEntry : testTable) {
+ System.out.println("sharedBaseAddress = " + testEntry);
+
+ OutputAnalyzer dumpOutput = TestCommon.dump(
+ appJar, new String[] {"Hello"}, "-XX:SharedBaseAddress=" + testEntry);
+ TestCommon.checkDump(dumpOutput, "Loading classes to share");
+
+ OutputAnalyzer execOutput = TestCommon.exec(appJar, "Hello");
+ TestCommon.checkExec(execOutput, "Hello World");
+ }
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/TestCommon.java b/hotspot/test/runtime/appcds/TestCommon.java
new file mode 100644
index 00000000..4ed416fe
--- /dev/null
+++ b/hotspot/test/runtime/appcds/TestCommon.java
@@ -0,0 +1,363 @@
+/*
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.cds.CDSTestUtils;
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Date;
+
+/**
+ * This is a test utility class for common AppCDS test functionality.
+ *
+ * Various methods use (String ...) for passing VM options. Note that the order
+ * of the VM options are important in certain cases. Many methods take arguments like
+ *
+ * (String prefix[], String suffix[], String... opts)
+ *
+ * Note that the order of the VM options is:
+ *
+ * prefix + opts + suffix
+ */
+public class TestCommon extends CDSTestUtils {
+ private static final String JSA_FILE_PREFIX = System.getProperty("user.dir") +
+ File.separator + "appcds-";
+
+ private static final SimpleDateFormat timeStampFormat =
+ new SimpleDateFormat("HH'h'mm'm'ss's'SSS");
+
+ private static final String timeoutFactor =
+ System.getProperty("test.timeout.factor", "1.0");
+
+ private static String currentArchiveName;
+
+ // Call this method to start new archive with new unique name
+ public static void startNewArchiveName() {
+ deletePriorArchives();
+ currentArchiveName = JSA_FILE_PREFIX +
+ timeStampFormat.format(new Date()) + ".jsa";
+ }
+
+ // Call this method to get current archive name
+ public static String getCurrentArchiveName() {
+ return currentArchiveName;
+ }
+
+ public static void setCurrentArchiveName(String archiveName) {
+ currentArchiveName = archiveName;
+ }
+
+ // Attempt to clean old archives to preserve space
+ // Archives are large artifacts (20Mb or more), and much larger than
+ // most other artifacts created in jtreg testing.
+ // Therefore it is a good idea to clean the old archives when they are not needed.
+ // In most cases the deletion attempt will succeed; on rare occasion the
+ // delete operation will fail since the system or VM process still holds a handle
+ // to the file; in such cases the File.delete() operation will silently fail, w/o
+ // throwing an exception, thus allowing testing to continue.
+ public static void deletePriorArchives() {
+ File dir = new File(System.getProperty("user.dir"));
+ String files[] = dir.list();
+ for (String name : files) {
+ if (name.startsWith("appcds-") && name.endsWith(".jsa")) {
+ if (!(new File(dir, name)).delete())
+ System.out.println("deletePriorArchives(): delete failed for file " + name);
+ }
+ }
+ }
+
+
+ // Create AppCDS archive using most common args - convenience method
+ // Legacy name preserved for compatibility
+ public static OutputAnalyzer dump(String appJar, String appClasses[],
+ String... suffix) throws Exception {
+ return createArchive(appJar, appClasses, suffix);
+ }
+
+
+ // Create AppCDS archive using most common args - convenience method
+ public static OutputAnalyzer createArchive(String appJar, String appClasses[],
+ String... suffix) throws Exception {
+ AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar)
+ .setAppClasses(appClasses);
+ opts.addSuffix(suffix);
+ return createArchive(opts);
+ }
+
+ public static String[] makeCommandLineForAppCDS(String... args) throws Exception {
+ return args;
+ }
+
+ // Create AppCDS archive using appcds options
+ public static OutputAnalyzer createArchive(AppCDSOptions opts)
+ throws Exception {
+
+ ArrayList<String> cmd = new ArrayList<String>();
+ File classList = makeClassList(opts.appClasses);
+ startNewArchiveName();
+
+ for (String p : opts.prefix) cmd.add(p);
+
+ if (opts.appJar != null) {
+ cmd.add("-cp");
+ cmd.add(opts.appJar);
+ } else {
+ cmd.add("-cp");
+ cmd.add("\"\"");
+ }
+
+ cmd.add("-Xshare:dump");
+// cmd.add("-Xlog:cds,cds+hashtables"); comment out because it will be run by jdk1.8
+ cmd.add("-XX:ExtraSharedClassListFile=" + classList.getPath());
+
+ if (opts.archiveName == null)
+ opts.archiveName = getCurrentArchiveName();
+
+ cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
+
+ for (String s : opts.suffix) cmd.add(s);
+
+ String[] cmdLine = cmd.toArray(new String[cmd.size()]);
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, makeCommandLineForAppCDS(cmdLine));
+ return executeAndLog(pb, "dump");
+ }
+
+
+ // Execute JVM using AppCDS archive with specified AppCDSOptions
+ public static OutputAnalyzer runWithArchive(AppCDSOptions opts)
+ throws Exception {
+
+ ArrayList<String> cmd = new ArrayList<String>();
+
+ for (String p : opts.prefix) cmd.add(p);
+
+ cmd.add("-Xshare:" + opts.xShareMode);
+ cmd.add("-showversion");
+ cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName());
+ cmd.add("-Dtest.timeout.factor=" + timeoutFactor);
+
+ if (opts.appJar != null) {
+ cmd.add("-cp");
+ cmd.add(opts.appJar);
+ }
+
+ for (String s : opts.suffix) cmd.add(s);
+
+ String[] cmdLine = cmd.toArray(new String[cmd.size()]);
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, makeCommandLineForAppCDS(cmdLine));
+ return executeAndLog(pb, "exec");
+ }
+
+
+ public static OutputAnalyzer execCommon(String... suffix) throws Exception {
+ AppCDSOptions opts = (new AppCDSOptions());
+ opts.addSuffix(suffix);
+ return runWithArchive(opts);
+ }
+
+ // This is the new API for running a Java process with CDS enabled.
+ // See comments in the CDSTestUtils.Result class for how to use this method.
+ public static Result run(String... suffix) throws Exception {
+ AppCDSOptions opts = (new AppCDSOptions());
+ opts.addSuffix(suffix);
+ return new Result(opts, runWithArchive(opts));
+ }
+
+ public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception {
+ AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar);
+ opts.addSuffix(suffix);
+ return runWithArchive(opts);
+ }
+
+ public static Result runWithModules(String prefix[], String upgrademodulepath, String modulepath,
+ String mid, String... testClassArgs) throws Exception {
+ AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath,
+ mid, testClassArgs);
+ return new Result(opts, runWithArchive(opts));
+ }
+
+ public static OutputAnalyzer execAuto(String... suffix) throws Exception {
+ AppCDSOptions opts = (new AppCDSOptions());
+ opts.addSuffix(suffix).setXShareMode("auto");
+ return runWithArchive(opts);
+ }
+
+ public static OutputAnalyzer execOff(String... suffix) throws Exception {
+ AppCDSOptions opts = (new AppCDSOptions());
+ opts.addSuffix(suffix).setXShareMode("off");
+ return runWithArchive(opts);
+ }
+
+
+ private static AppCDSOptions makeModuleOptions(String prefix[], String upgrademodulepath, String modulepath,
+ String mid, String testClassArgs[]) {
+ AppCDSOptions opts = (new AppCDSOptions());
+
+ opts.addPrefix(prefix);
+ if (upgrademodulepath == null) {
+ opts.addSuffix("-p", modulepath, "-m", mid);
+ } else {
+ opts.addSuffix("--upgrade-module-path", upgrademodulepath,
+ "-p", modulepath, "-m", mid);
+ }
+ opts.addSuffix(testClassArgs);
+ return opts;
+ }
+
+ public static OutputAnalyzer execModule(String prefix[], String upgrademodulepath, String modulepath,
+ String mid, String... testClassArgs)
+ throws Exception {
+ AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath,
+ mid, testClassArgs);
+ return runWithArchive(opts);
+ }
+
+
+ // A common operation: dump, then check results
+ public static OutputAnalyzer testDump(String appJar, String appClasses[],
+ String... suffix) throws Exception {
+ OutputAnalyzer output = dump(appJar, appClasses, suffix);
+ output.shouldContain("Loading classes to share");
+ output.shouldHaveExitValue(0);
+ return output;
+ }
+
+
+ /**
+ * Simple test -- dump and execute appJar with the given appClasses in classlist.
+ */
+ public static OutputAnalyzer test(String appJar, String appClasses[], String... args)
+ throws Exception {
+ testDump(appJar, appClasses);
+
+ OutputAnalyzer output = exec(appJar, args);
+ return checkExec(output);
+ }
+
+
+ public static OutputAnalyzer checkExecReturn(OutputAnalyzer output, int ret,
+ boolean checkContain, String... matches) throws Exception {
+ try {
+ for (String s : matches) {
+ if (checkContain) {
+ output.shouldContain(s);
+ } else {
+ output.shouldNotContain(s);
+ }
+ }
+ output.shouldHaveExitValue(ret);
+ } catch (Exception e) {
+ checkCommonExecExceptions(output, e);
+ }
+
+ return output;
+ }
+
+
+ // Convenience concatenation utils
+ public static String[] list(String ...args) {
+ return args;
+ }
+
+
+ public static String[] list(String arg, int count) {
+ ArrayList<String> stringList = new ArrayList<String>();
+ for (int i = 0; i < count; i++) {
+ stringList.add(arg);
+ }
+
+ String outputArray[] = stringList.toArray(new String[stringList.size()]);
+ return outputArray;
+ }
+
+
+ public static String[] concat(String... args) {
+ return list(args);
+ }
+
+
+ public static String[] concat(String prefix[], String... extra) {
+ ArrayList<String> list = new ArrayList<String>();
+ for (String s : prefix) {
+ list.add(s);
+ }
+ for (String s : extra) {
+ list.add(s);
+ }
+
+ return list.toArray(new String[list.size()]);
+ }
+
+
+ // ===================== Concatenate paths
+ public static String concatPaths(String... paths) {
+ String prefix = "";
+ String s = "";
+ for (String p : paths) {
+ s += prefix;
+ s += p;
+ prefix = File.pathSeparator;
+ }
+ return s;
+ }
+
+
+ public static String getTestJar(String jar) {
+ File jarFile = CDSTestUtils.getTestArtifact(jar, true);
+ if (!jarFile.isFile()) {
+ throw new RuntimeException("Not a regular file: " + jarFile.getPath());
+ }
+ return jarFile.getPath();
+ }
+
+
+ public static String getTestDir(String d) {
+ File dirFile = CDSTestUtils.getTestArtifact(d, true);
+ if (!dirFile.isDirectory()) {
+ throw new RuntimeException("Not a directory: " + dirFile.getPath());
+ }
+ return dirFile.getPath();
+ }
+
+ public static boolean checkOutputStrings(String outputString1,
+ String outputString2,
+ String split_regex) {
+ String[] sa1 = outputString1.split(split_regex);
+ String[] sa2 = outputString2.split(split_regex);
+ Arrays.sort(sa1);
+ Arrays.sort(sa2);
+
+ int i = 0;
+ for (String s : sa1) {
+ if (!s.equals(sa2[i])) {
+ throw new RuntimeException(s + " is different from " + sa2[i]);
+ }
+ i ++;
+ }
+ return true;
+ }
+}
diff --git a/hotspot/test/runtime/appcds/TraceLongClasspath.java b/hotspot/test/runtime/appcds/TraceLongClasspath.java
new file mode 100644
index 00000000..e25fcd37
--- /dev/null
+++ b/hotspot/test/runtime/appcds/TraceLongClasspath.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary ensure -XX:+TraceClassPaths showing entire expecting app classpath
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main TraceLongClasspath
+ */
+
+import java.io.File;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class TraceLongClasspath {
+
+ final static String ps = File.pathSeparator;
+
+ public static void main(String[] args) throws Exception {
+ String appJar = JarBuilder.getOrCreateHelloJar();
+
+ String longClassPath =
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/user-patch.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/abc-startup.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/modules/features/com.foobar.db.jdbc7-dms.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/jdk/lib/tools.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/aaserver/server/lib/someapps.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/aaserver/../foobar_common/modules/net.xy.batcontrib_1.1.0.0_1-0b3/lib/bat-contrib.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/aaserver/modules/features/foobar.aas.common.kkkkkkkkkkk.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.common.adapters_11.1.1/foobar.abc.common.adapters.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.plane.adapter_12.1.3/foobar.plane.adapter.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/lib/ccccccccar-common.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/communications/modules/config.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/communications/modules/userprefs-config.jar" + ps +
+ "/scratch/xxxx/yyyy/XXXXXX/aaaaaaaa/xxxxxxx/xxxxxxxx.us.foobar.com/CommonDomain/config/abc-infra" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/qqqqqq-all-1.6.5.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.thread_11.1.1/foobar.abc.thread.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.thread_11.1.1/thread-rrrrrrr-ext-aas.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.adapter_11.1.1/foobar.abc.adapter.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.ccc_11.1.1/foobar.abc.ccc.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/bbb/lib/commons-configuration.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/bbb/lib/commons-lang.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/bbb/lib/commons-logging.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/modules/foobar.wccore/foobar-ppppppp-api.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/modules/foobar.ooo_12.1.3/ooo-manifest.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/modules/internal/features/rrr_aaxyxx_foobar.rrr.aas.classpath.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.thread_11.1.1/rrrrrrrr-api.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/commons-xxx-1.1.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/abc/abc/modules/foobar.abc.mgmt_11.1.1/abc-infra-mgmt.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/eee/archives/eee-eee.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/aaserver/common/march/lib/marchnet.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/aaserver/common/march/lib/marchclient.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/aaserver/common/march/lib/march.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/wwcontent/cde/iii/jlib/iiiloader.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/wwcontent/cde/iii/components/xxxxxxyyzzzzz/classes-xxxxxxyyzzzzz.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/wwcontent/cde/iii/components/mmmmmmm/lib/abc_core.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/wwcontent/cde/iii/components/mmmmmmm/lib/abc_codec.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/wwcontent/cde/iii/components/mmmmmmm/lib/abc_imageio.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/jdk/lib/tools.jar" + ps +
+ "/scratch/xxxx/yyyy/ZZZZZZ/aaaaaaaaaa/xx/foobar_common/modules/foobar.ooo_12.1.3/ooo-manifest.jar";
+
+ String myCP = longClassPath + ps + appJar;
+ // Dump an archive with a specified JAR file in -classpath
+ TestCommon.testDump(myCP, TestCommon.list("Hello"));
+
+ TestCommon.run(
+ "-XX:+TraceClassPaths",
+ "-cp", appJar,
+ "Hello");
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/WideIloadTest.java b/hotspot/test/runtime/appcds/WideIloadTest.java
new file mode 100644
index 00000000..9c045882
--- /dev/null
+++ b/hotspot/test/runtime/appcds/WideIloadTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/**
+ * @test
+ * @summary Test 'iload_w' bytecode in shared class
+ * @library /testlibrary
+ * @compile test-classes/Iloadw.jasm
+ * @compile test-classes/IloadwMain.java
+ * @run main WideIloadTest
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class WideIloadTest {
+ public static void main(String args[]) throws Exception {
+ JarBuilder.build("iload_w", "Iloadw", "IloadwMain");
+ String appJar = TestCommon.getTestJar("iload_w.jar");
+ OutputAnalyzer dumpOutput = TestCommon.dump(appJar, TestCommon.list(
+ "Iloadw", "IloadwMain"));
+ TestCommon.checkDump(dumpOutput);
+ OutputAnalyzer execOutput = TestCommon.exec(appJar, "IloadwMain");
+ TestCommon.checkExec(execOutput, "Passed");
+ }
+}
diff --git a/hotspot/test/runtime/appcds/XShareAutoWithChangedJar.java b/hotspot/test/runtime/appcds/XShareAutoWithChangedJar.java
new file mode 100644
index 00000000..f59f2f89
--- /dev/null
+++ b/hotspot/test/runtime/appcds/XShareAutoWithChangedJar.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @summary Test -Xshare:auto for AppCDS
+ * @library /testlibrary
+ * @compile test-classes/Hello.java
+ * @run main XShareAutoWithChangedJar
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+public class XShareAutoWithChangedJar {
+ public static void main(String[] args) throws Exception {
+ String appJar = JarBuilder.build("XShareAutoWithChangedJar", "Hello");
+
+ // 1. dump
+ OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list("Hello"));
+ TestCommon.checkDump(output);
+
+ // 2. change the jar
+ JarBuilder.build("XShareAutoWithChangedJar", "Hello");
+
+ // 3. exec
+ output = TestCommon.execAuto("-cp", appJar, "Hello");
+ output.shouldContain("Hello World");
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/test-classes/C1.java b/hotspot/test/runtime/appcds/test-classes/C1.java
new file mode 100644
index 00000000..86201cd4
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/C1.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sealed.pkg;
+
+public class C1 {
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/C2.java b/hotspot/test/runtime/appcds/test-classes/C2.java
new file mode 100644
index 00000000..ad0026fb
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/C2.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package pkg;
+
+public class C2 {
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/CheckIfShared.java b/hotspot/test/runtime/appcds/test-classes/CheckIfShared.java
new file mode 100644
index 00000000..59b91f48
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/CheckIfShared.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+import sun.hotspot.WhiteBox;
+
+public class CheckIfShared {
+ public static void main(String args[]) throws Exception {
+ WhiteBox wb = WhiteBox.getWhiteBox();
+ if ("true".equals(args[0])) {
+ if (!wb.isSharedClass(CheckIfShared.class)) {
+ throw new RuntimeException("wb.isSharedClass(CheckIfShared.class) should be true");
+ }
+ } else {
+ if (wb.isSharedClass(CheckIfShared.class)) {
+ throw new RuntimeException("wb.isSharedClass(CheckIfShared.class) should be false");
+ }
+ }
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/test-classes/Hello.java b/hotspot/test/runtime/appcds/test-classes/Hello.java
new file mode 100644
index 00000000..dc134771
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/Hello.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+public class Hello {
+ public static void main(String args[]) {
+ System.out.println("Hello World");
+ }
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/HelloMore.java b/hotspot/test/runtime/appcds/test-classes/HelloMore.java
new file mode 100644
index 00000000..0d8f335e
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/HelloMore.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+public class HelloMore {
+ public static void main(String args[]) {
+ Hello.main(args);
+ System.out.println("Hello World ... More");
+ }
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/Iloadw.jasm b/hotspot/test/runtime/appcds/test-classes/Iloadw.jasm
new file mode 100644
index 00000000..5c1fffbf
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/Iloadw.jasm
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+public class Iloadw
+ version 51: 0
+{
+ public static Method run:"()I"
+ stack 1 locals 400
+ {
+ iconst_0;
+ istore_w 300;
+ iinc_w 300,1;
+ iload_w 300;
+ ireturn;
+ }
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/IloadwMain.java b/hotspot/test/runtime/appcds/test-classes/IloadwMain.java
new file mode 100644
index 00000000..7257cce6
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/IloadwMain.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+public class IloadwMain {
+ public static void main(String args[]) {
+ int result = Iloadw.run();
+ if (result != 1) {
+ throw new RuntimeException(
+ "Failed. Result is " + result + ", expect 1.");
+ } else {
+ System.out.println("Passed.");
+ }
+ }
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/MissingSuper.java b/hotspot/test/runtime/appcds/test-classes/MissingSuper.java
new file mode 100644
index 00000000..ef47a7cb
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/MissingSuper.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+public class MissingSuper {
+ public static void main(String args[]) {
+ try {
+ new MissingSuperSub();
+ } catch (NoClassDefFoundError e) {
+ System.out.println("Expected NoClassDefFoundError:");
+ e.printStackTrace(System.out);
+ }
+
+ try {
+ new MissingSuperImpl();
+ } catch (NoClassDefFoundError e) {
+ System.out.println("Expected NoClassDefFoundError:");
+ e.printStackTrace(System.out);
+ }
+ }
+}
+
+class MissingSuperSup {} // This class will be deleted from missing_super.jar before dumping
+
+class MissingSuperSub extends MissingSuperSup {}
+
+interface MissingSuperIntf {} // This interface will be deleted from missing_super.jar before dumping
+
+class MissingSuperImpl implements MissingSuperIntf {}
diff --git a/hotspot/test/runtime/appcds/test-classes/PackageSealingTest.java b/hotspot/test/runtime/appcds/test-classes/PackageSealingTest.java
new file mode 100644
index 00000000..a1e8ea0a
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/PackageSealingTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+import java.lang.Package;
+
+public class PackageSealingTest {
+ public static void main(String args[]) {
+ try {
+ Class c1 = PackageSealingTest.class.forName("sealed.pkg.C1");
+ Class c2 = PackageSealingTest.class.forName("pkg.C2");
+ Package p1 = c1.getPackage();
+ System.out.println("Package 1: " + p1.toString());
+ Package p2 = c2.getPackage();
+ System.out.println("Package 2: " + p2.toString());
+
+ if (!p1.isSealed()) {
+ System.out.println("Failed: sealed.pkg is not sealed.");
+ System.exit(0);
+ }
+
+ if (p2.isSealed()) {
+ System.out.println("Failed: pkg is sealed.");
+ System.exit(0);
+ }
+
+ System.out.println("OK");
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ }
+}
diff --git a/hotspot/test/runtime/appcds/test-classes/ParallelClasses.java b/hotspot/test/runtime/appcds/test-classes/ParallelClasses.java
new file mode 100644
index 00000000..a4d0520f
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/ParallelClasses.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+class ParallelClass0 {}
+class ParallelClass1 {}
+class ParallelClass2 {}
+class ParallelClass3 {}
+class ParallelClass4 {}
+class ParallelClass5 {}
+class ParallelClass6 {}
+class ParallelClass7 {}
+class ParallelClass8 {}
+class ParallelClass9 {}
+class ParallelClass10 {}
+class ParallelClass11 {}
+class ParallelClass12 {}
+class ParallelClass13 {}
+class ParallelClass14 {}
+class ParallelClass15 {}
+class ParallelClass16 {}
+class ParallelClass17 {}
+class ParallelClass18 {}
+class ParallelClass19 {}
+class ParallelClass20 {}
+class ParallelClass21 {}
+class ParallelClass22 {}
+class ParallelClass23 {}
+class ParallelClass24 {}
+class ParallelClass25 {}
+class ParallelClass26 {}
+class ParallelClass27 {}
+class ParallelClass28 {}
+class ParallelClass29 {}
+class ParallelClass30 {}
+class ParallelClass31 {}
+class ParallelClass32 {}
+class ParallelClass33 {}
+class ParallelClass34 {}
+class ParallelClass35 {}
+class ParallelClass36 {}
+class ParallelClass37 {}
+class ParallelClass38 {}
+class ParallelClass39 {}
diff --git a/hotspot/test/runtime/appcds/test-classes/ParallelLoad.java b/hotspot/test/runtime/appcds/test-classes/ParallelLoad.java
new file mode 100644
index 00000000..9a6fe550
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/ParallelLoad.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+import java.io.*;
+import java.net.*;
+import java.lang.reflect.Field;
+
+
+// This test helper is parameterized by:
+// - class transformation mode: property "appcds.parallel.transform.mode"
+// - class loader test types
+//
+// In the case of transformMode == "cflh", the transformation is performed
+// by AppCDS/jvmti/TransformerAgent.java. The classes to be transformed, such as
+// ParallelClassTr0, are defined in ./jvmti/parallelLoad/ParallelClasses.java
+
+public class ParallelLoad {
+ public static int MAX_CLASSES = 40;
+ public static int NUM_THREADS = 4;
+
+ public final static int SYSTEM_LOADER = 0;
+ public final static int SINGLE_CUSTOM_LOADER = 1;
+ public final static int MULTI_CUSTOM_LOADER = 2;
+
+ public static final int FINGERPRINT_MODE = 1;
+ public static final int API_MODE = 2;
+
+ public static int loaderType = SYSTEM_LOADER;
+ public static ClassLoader classLoaders[];
+ public static int mode = FINGERPRINT_MODE;
+
+ public static float timeoutFactor =
+ Float.parseFloat(System.getProperty("test.timeout.factor", "1.0"));
+
+ public static void main(String args[]) throws Throwable {
+ run(args, null);
+ }
+ public static void run(String args[], ClassLoader loaders[]) throws Throwable {
+ String customJar = null;
+ System.out.println("ParallelLoad: timeoutFactor = " + timeoutFactor);
+
+ if (args.length >= 1) {
+ if ("SINGLE_CUSTOM_LOADER".equals(args[0])) {
+ loaderType = SINGLE_CUSTOM_LOADER;
+ customJar = args[2];
+ } else if ("MULTI_CUSTOM_LOADER".equals(args[0])) {
+ loaderType = MULTI_CUSTOM_LOADER;
+ customJar = args[2];
+ } else if ("SYSTEM_LOADER".equals(args[0])) {
+ loaderType = SYSTEM_LOADER;
+ } else {
+ throw new RuntimeException("Unexpected loaderType" + args[0]);
+ }
+ }
+
+ if (customJar != null) {
+ if ("FINGERPRINT_MODE".equals(args[1])) {
+ mode = FINGERPRINT_MODE;
+ classLoaders = new ClassLoader[NUM_THREADS];
+ for (int i=0; i<NUM_THREADS; i++) {
+ URL url = new File(customJar).toURI().toURL();
+ URL[] urls = new URL[] {url};
+ classLoaders[i] = new URLClassLoader(urls);
+ }
+ } else {
+ // Loaders must be supplied by caller of the run() method
+ mode = API_MODE;
+ classLoaders = loaders;
+ }
+ }
+
+ System.out.println("Start Parallel Load ...");
+
+ Thread thread[] = new Thread[NUM_THREADS];
+ for (int i=0; i<NUM_THREADS; i++) {
+ Thread t = new ParallelLoadThread(i);
+ t.start();
+ thread[i] = t;
+ }
+
+ Thread watchdog = new ParallelLoadWatchdog();
+ watchdog.setDaemon(true);
+ watchdog.start();
+
+ for (int i=0; i<NUM_THREADS; i++) {
+ thread[i].join();
+ }
+ System.out.println("Parallel Load ... done");
+ System.exit(0);
+ }
+}
+
+
+class ParallelLoadWatchdog extends Thread {
+ public void run() {
+ try {
+ long timeout = (long) (20 * 1000 * ParallelLoad.timeoutFactor);
+ Thread.sleep(timeout);
+ System.out.println("ParallelLoadWatchdog: Timeout reached: timeout(ms) = " + timeout);
+ System.exit(1);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ System.exit(1);
+ }
+ }
+};
+
+
+class ParallelLoadThread extends Thread {
+ static int num_ready[] = new int[ParallelLoad.MAX_CLASSES];
+ static Object lock = new Object();
+ static String transformMode =
+ System.getProperty("appcds.parallel.transform.mode", "none");
+
+ int thread_id;
+ ParallelLoadThread(int thread_id) {
+ this.thread_id = thread_id;
+ }
+
+ public void run() {
+ try {
+ run0();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ private static void log(String msg, Object... args) {
+ String msg0 = "ParallelLoadThread: " + String.format(msg, args);
+ System.out.println(msg0);
+ }
+
+ private void run0() throws Throwable {
+ for (int i=0; i<ParallelLoad.MAX_CLASSES; i++) {
+ synchronized(lock) {
+ num_ready[i] ++;
+ while (num_ready[i] < ParallelLoad.NUM_THREADS) {
+ lock.wait();
+ }
+ lock.notifyAll();
+ }
+ log("this = %s %d", this, i);
+ String className = "ParallelClass" + i;
+ if (transformMode.equals("cflh"))
+ className = "ParallelClassTr" + i;
+
+ Class clazz = null;
+
+ switch (ParallelLoad.loaderType) {
+ case ParallelLoad.SYSTEM_LOADER:
+ clazz = Class.forName(className);
+ break;
+ case ParallelLoad.SINGLE_CUSTOM_LOADER:
+ clazz = ParallelLoad.classLoaders[0].loadClass(className);
+ break;
+ case ParallelLoad.MULTI_CUSTOM_LOADER:
+ clazz = ParallelLoad.classLoaders[thread_id].loadClass(className);
+ break;
+ }
+
+ log("clazz = %s", clazz);
+ testTransformation(clazz);
+ }
+ }
+
+ private void testTransformation(Class c) throws Exception {
+ if (transformMode.equals("none"))
+ return;
+
+ // currently only cflh transform mode is supported
+ if (!transformMode.equals("cflh")) {
+ String msg = "wrong transform mode: " + transformMode;
+ throw new IllegalArgumentException(msg);
+ }
+
+ Field[] fields = c.getFields();
+ boolean fieldFound = false;
+ for (Field f : fields) {
+ if (f.getName().equals("testString")) {
+ checkTransformationString(c, (String) f.get(null));
+ fieldFound = true;
+ }
+ }
+
+ if (!fieldFound)
+ throw new RuntimeException ("Expected field 'testString' not found");
+ }
+
+ private void checkTransformationString(Class c, String actual) throws Exception {
+ String expected = "class-transform-check: this-has-been--transformed";
+ if (!actual.equals(expected)) {
+ String msg1 = "Transformation failed for class" + c.getName();
+ String msg2 = String.format("Expected: %s, actual: %s", expected, actual);
+ throw new RuntimeException(msg1 + "\n" + msg2);
+ }
+ }
+}
+
diff --git a/hotspot/test/runtime/appcds/test-classes/package_seal.mf b/hotspot/test/runtime/appcds/test-classes/package_seal.mf
new file mode 100644
index 00000000..e34c7ab5
--- /dev/null
+++ b/hotspot/test/runtime/appcds/test-classes/package_seal.mf
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Created-By: 1.9.0-internal (Oracle Corporation)
+
+Name: sealed/pkg/
+Sealed: true
diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java
index 67806cab..2132325f 100644
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java
@@ -164,6 +164,21 @@ public final class OutputAnalyzer {
return this;
}
+ /**
+ * Verify the exit value of the process
+ * backport from jdk11u
+ * @param notExpectedExitValue Unexpected exit value from process
+ * @throws RuntimeException If the exit value from the process did match the expected value
+ */
+ public OutputAnalyzer shouldNotHaveExitValue(int notExpectedExitValue) {
+ if (getExitValue() == notExpectedExitValue) {
+ reportDiagnosticSummary();
+ throw new RuntimeException("Unexpected to get exit value of ["
+ + notExpectedExitValue + "]\n");
+ }
+ return this;
+ }
+
/**
* Verify that the stdout and stderr contents of output buffer does not contain the string
*
diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java
index 902e3b13..be48a7e6 100644
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java
@@ -370,4 +370,57 @@ public final class Utils {
}
return new String(hexView);
}
+
+ // This method is intended to be called from a jtreg test.
+ // It will identify the name of the test by means of stack walking.
+ // It can handle both jtreg tests and a testng tests wrapped inside jtreg tests.
+ // For jtreg tests the name of the test will be searched by stack-walking
+ // until the method main() is found; the class containing that method is the
+ // main test class and will be returned as the name of the test.
+ // Special handling is used for testng tests.
+ // backport from jdk11u
+ public static String getTestName() {
+ String result = null;
+ // If we are using testng, then we should be able to load the "Test" annotation.
+ Class testClassAnnotation;
+
+ try {
+ testClassAnnotation = Class.forName("org.testng.annotations.Test");
+ } catch (ClassNotFoundException e) {
+ testClassAnnotation = null;
+ }
+
+ StackTraceElement[] elms = (new Throwable()).getStackTrace();
+ for (StackTraceElement n: elms) {
+ String className = n.getClassName();
+
+ // If this is a "main" method, then use its class name, but only
+ // if we are not using testng.
+ if (testClassAnnotation == null && "main".equals(n.getMethodName())) {
+ result = className;
+ break;
+ }
+
+ // If this is a testng test, the test will have no "main" method. We can
+ // detect a testng test class by looking for the org.testng.annotations.Test
+ // annotation. If present, then use the name of this class.
+ if (testClassAnnotation != null) {
+ try {
+ Class c = Class.forName(className);
+ if (c.isAnnotationPresent(testClassAnnotation)) {
+ result = className;
+ break;
+ }
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Unexpected exception: " + e, e);
+ }
+ }
+ }
+
+ if (result == null) {
+ throw new RuntimeException("Couldn't find main test class in stack trace");
+ }
+
+ return result;
+ }
}
diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/cds/CDSOptions.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/cds/CDSOptions.java
new file mode 100644
index 00000000..09050d6c
--- /dev/null
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/cds/CDSOptions.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.java.testlibrary.cds;
+
+import java.util.ArrayList;
+
+// This class represents options used
+// during creation of CDS archive and/or running JVM with a CDS archive
+public class CDSOptions {
+ public String xShareMode = "on";
+ public String archiveName;
+ public ArrayList<String> prefix = new ArrayList<String>();
+ public ArrayList<String> suffix = new ArrayList<String>();
+
+ // Indicate whether to append "-version" when using CDS Archive.
+ // Most of tests will use '-version'
+ public boolean useVersion = true;
+
+
+ public CDSOptions() {
+ }
+
+
+ public CDSOptions addPrefix(String... prefix) {
+ for (String s : prefix) this.prefix.add(s);
+ return this;
+ }
+
+
+ public CDSOptions addSuffix(String... suffix) {
+ for (String s : suffix) this.suffix.add(s);
+ return this;
+ }
+
+ public CDSOptions setXShareMode(String mode) {
+ this.xShareMode = mode;
+ return this;
+ }
+
+
+ public CDSOptions setArchiveName(String name) {
+ this.archiveName = name;
+ return this;
+ }
+
+
+ public CDSOptions setUseVersion(boolean use) {
+ this.useVersion = use;
+ return this;
+ }
+}
diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/cds/CDSTestUtils.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/cds/CDSTestUtils.java
new file mode 100644
index 00000000..f1ff7e48
--- /dev/null
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/cds/CDSTestUtils.java
@@ -0,0 +1,590 @@
+/*
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.java.testlibrary.cds;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.Utils;
+
+
+// This class contains common test utilities for testing CDS
+public class CDSTestUtils {
+ public static final String MSG_RANGE_NOT_WITHIN_HEAP =
+ "UseSharedSpaces: Unable to allocate region, range is not within java heap.";
+ public static final String MSG_RANGE_ALREADT_IN_USE =
+ "Unable to allocate region, java heap range is already in use.";
+ public static final String MSG_COMPRESSION_MUST_BE_USED =
+ "Unable to use shared archive: UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.";
+
+ public interface Checker {
+ public void check(OutputAnalyzer output) throws Exception;
+ }
+
+ /*
+ * INTRODUCTION
+ *
+ * When testing various CDS functionalities, we need to launch JVM processes
+ * using a "launch method" (such as TestCommon.run), and analyze the results of these
+ * processes.
+ *
+ * While typical jtreg tests would use OutputAnalyzer in such cases, due to the
+ * complexity of CDS failure modes, we have added the CDSTestUtils.Result class
+ * to make the analysis more convenient and less error prone.
+ *
+ * A Java process can end in one of the following 4 states:
+ *
+ * 1: Unexpected error - such as JVM crashing. In this case, the "launch method"
+ * will throw a RuntimeException.
+ * 2: Mapping Failure - this happens when the OS (intermittently) fails to map the
+ * CDS archive, normally caused by Address Space Layout Randomization.
+ * We usually treat this as "pass".
+ * 3: Normal Exit - the JVM process has finished without crashing, and the exit code is 0.
+ * 4: Abnormal Exit - the JVM process has finished without crashing, and the exit code is not 0.
+ *
+ * In most test cases, we need to check the JVM process's output in cases 3 and 4. However, we need
+ * to make sure that our test code is not confused by case 2.
+ *
+ * For example, a JVM process is expected to print the string "Hi" and exit with 0. With the old
+ * CDSTestUtils.runWithArchive API, the test may be written as this:
+ *
+ * OutputAnalyzer out = CDSTestUtils.runWithArchive(args);
+ * out.shouldContain("Hi");
+ *
+ * However, if the JVM process fails with mapping failure, the string "Hi" will not be in the output,
+ * and your test case will fail intermittently.
+ *
+ * Instead, the test case should be written as
+ *
+ * CCDSTestUtils.run(args).assertNormalExit("Hi");
+ *
+ * EXAMPLES/HOWTO
+ *
+ * 1. For simple substring matching:
+ *
+ * CCDSTestUtils.run(args).assertNormalExit("Hi");
+ * CCDSTestUtils.run(args).assertNormalExit("a", "b", "x");
+ * CCDSTestUtils.run(args).assertAbnormalExit("failure 1", "failure2");
+ *
+ * 2. For more complex output matching: using Lambda expressions
+ *
+ * CCDSTestUtils.run(args)
+ * .assertNormalExit(output -> output.shouldNotContain("this should not be printed");
+ * CCDSTestUtils.run(args)
+ * .assertAbnormalExit(output -> {
+ * output.shouldNotContain("this should not be printed");
+ * output.shouldHaveExitValue(123);
+ * });
+ *
+ * 3. Chaining several checks:
+ *
+ * CCDSTestUtils.run(args)
+ * .assertNormalExit(output -> output.shouldNotContain("this should not be printed")
+ * .assertNormalExit("should have this", "should have that");
+ *
+ * 4. [Rare use case] if a test sometimes exit normally, and sometimes abnormally:
+ *
+ * CCDSTestUtils.run(args)
+ * .ifNormalExit("ths string is printed when exiting with 0")
+ * .ifAbNormalExit("ths string is printed when exiting with 1");
+ *
+ * NOTE: you usually don't want to write your test case like this -- it should always
+ * exit with the same exit code. (But I kept this API because some existing test cases
+ * behave this way -- need to revisit).
+ */
+ public static class Result {
+ private final OutputAnalyzer output;
+ private final CDSOptions options;
+ private final boolean hasMappingFailure;
+ private final boolean hasAbnormalExit;
+ private final boolean hasNormalExit;
+ private final String CDS_DISABLED = "warning: CDS is disabled when the";
+
+ public Result(CDSOptions opts, OutputAnalyzer out) throws Exception {
+ options = opts;
+ output = out;
+ hasMappingFailure = CDSTestUtils.checkCommonExecExceptions(output);
+ hasAbnormalExit = (!hasMappingFailure) && (output.getExitValue() != 0);
+ hasNormalExit = (!hasMappingFailure) && (output.getExitValue() == 0);
+
+ if (hasNormalExit) {
+ if ("on".equals(options.xShareMode) &&
+ output.getStderr().contains("java version") &&
+ !output.getStderr().contains(CDS_DISABLED)) {
+ // "-showversion" is always passed in the command-line by the execXXX methods.
+ // During normal exit, we require that the VM to show that sharing was enabled.
+ output.shouldContain("sharing");
+ }
+ }
+ }
+
+ public Result assertNormalExit(Checker checker) throws Exception {
+ if (!hasMappingFailure) {
+ checker.check(output);
+ output.shouldHaveExitValue(0);
+ }
+ return this;
+ }
+
+ public Result assertAbnormalExit(Checker checker) throws Exception {
+ if (!hasMappingFailure) {
+ checker.check(output);
+ output.shouldNotHaveExitValue(0);
+ }
+ return this;
+ }
+
+ // When {--limit-modules, --patch-module, and/or --upgrade-module-path}
+ // are specified, CDS is silently disabled for both -Xshare:auto and -Xshare:on.
+ public Result assertSilentlyDisabledCDS(Checker checker) throws Exception {
+ if (hasMappingFailure) {
+ throw new RuntimeException("Unexpected mapping failure");
+ }
+ // this comes from a JVM warning message.
+ output.shouldContain(CDS_DISABLED);
+
+ checker.check(output);
+ return this;
+ }
+
+ public Result assertSilentlyDisabledCDS(int exitCode, String... matches) throws Exception {
+ return assertSilentlyDisabledCDS((out) -> {
+ out.shouldHaveExitValue(exitCode);
+ checkMatches(out, matches);
+ });
+ }
+
+ public Result ifNormalExit(Checker checker) throws Exception {
+ if (hasNormalExit) {
+ checker.check(output);
+ }
+ return this;
+ }
+
+ public Result ifAbnormalExit(Checker checker) throws Exception {
+ if (hasAbnormalExit) {
+ checker.check(output);
+ }
+ return this;
+ }
+
+ public Result ifNoMappingFailure(Checker checker) throws Exception {
+ if (!hasMappingFailure) {
+ checker.check(output);
+ }
+ return this;
+ }
+
+
+ public Result assertNormalExit(String... matches) throws Exception {
+ if (!hasMappingFailure) {
+ checkMatches(output, matches);
+ output.shouldHaveExitValue(0);
+ }
+ return this;
+ }
+
+ public Result assertAbnormalExit(String... matches) throws Exception {
+ if (!hasMappingFailure) {
+ checkMatches(output, matches);
+ output.shouldNotHaveExitValue(0);
+ }
+
+ return this;
+ }
+ }
+
+ // Specify this property to copy sdandard output of the child test process to
+ // the parent/main stdout of the test.
+ // By default such output is logged into a file, and is copied into the main stdout.
+ public static final boolean CopyChildStdoutToMainStdout =
+ Boolean.valueOf(System.getProperty("test.cds.copy.child.stdout", "true"));
+
+ // This property is passed to child test processes
+ public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0");
+
+ public static final String UnableToMapMsg =
+ "Unable to map shared archive: test did not complete; assumed PASS";
+
+ // Create bootstrap CDS archive,
+ // use extra JVM command line args as a prefix.
+ // For CDS tests specifying prefix makes more sense than specifying suffix, since
+ // normally there are no classes or arguments to classes, just "-version"
+ // To specify suffix explicitly use CDSOptions.addSuffix()
+ public static OutputAnalyzer createArchive(String... cliPrefix)
+ throws Exception {
+ return createArchive((new CDSOptions()).addPrefix(cliPrefix));
+ }
+
+ // Create bootstrap CDS archive
+ public static OutputAnalyzer createArchive(CDSOptions opts)
+ throws Exception {
+
+ startNewArchiveName();
+
+ ArrayList<String> cmd = new ArrayList<String>();
+
+ for (String p : opts.prefix) cmd.add(p);
+
+ cmd.add("-Xshare:dump");
+ cmd.add("-Xlog:cds,cds+hashtables");
+ if (opts.archiveName == null)
+ opts.archiveName = getDefaultArchiveName();
+ cmd.add("-XX:SharedArchiveFile=./" + opts.archiveName);
+
+ for (String s : opts.suffix) cmd.add(s);
+
+ String[] cmdLine = cmd.toArray(new String[cmd.size()]);
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
+ return executeAndLog(pb, "dump");
+ }
+
+
+ // check result of 'dump-the-archive' operation, that is "-Xshare:dump"
+ public static OutputAnalyzer checkDump(OutputAnalyzer output, String... extraMatches)
+ throws Exception {
+
+ output.shouldContain("Loading classes to share");
+ output.shouldHaveExitValue(0);
+
+ for (String match : extraMatches) {
+ output.shouldContain(match);
+ }
+
+ return output;
+ }
+
+
+ // A commonly used convenience methods to create an archive and check the results
+ // Creates an archive and checks for errors
+ public static OutputAnalyzer createArchiveAndCheck(CDSOptions opts)
+ throws Exception {
+ return checkDump(createArchive(opts));
+ }
+
+
+ public static OutputAnalyzer createArchiveAndCheck(String... cliPrefix)
+ throws Exception {
+ return checkDump(createArchive(cliPrefix));
+ }
+
+
+ // This method should be used to check the output of child VM for common exceptions.
+ // Most of CDS tests deal with child VM processes for creating and using the archive.
+ // However exceptions that occur in the child process do not automatically propagate
+ // to the parent process. This mechanism aims to improve the propagation
+ // of exceptions and common errors.
+ // Exception e argument - an exception to be re-thrown if none of the common
+ // exceptions match. Pass null if you wish not to re-throw any exception.
+ public static boolean checkCommonExecExceptions(OutputAnalyzer output, Exception e)
+ throws Exception {
+ if (output.getStdout().contains("https://bugreport.java.com/bugreport/crash.jsp")) {
+ throw new RuntimeException("Hotspot crashed");
+ }
+ if (output.getStdout().contains("TEST FAILED")) {
+ throw new RuntimeException("Test Failed");
+ }
+ if (output.getOutput().contains("Unable to unmap shared space")) {
+ throw new RuntimeException("Unable to unmap shared space");
+ }
+
+ // Special case -- sometimes Xshare:on fails because it failed to map
+ // at given address. This behavior is platform-specific, machine config-specific
+ // and can be random (see ASLR).
+ if (isUnableToMap(output)) {
+ System.out.println(UnableToMapMsg);
+ return true;
+ }
+
+ if (e != null) {
+ throw e;
+ }
+ return false;
+ }
+
+ public static boolean checkCommonExecExceptions(OutputAnalyzer output) throws Exception {
+ return checkCommonExecExceptions(output, null);
+ }
+
+
+ // Check the output for indication that mapping of the archive failed.
+ // Performance note: this check seems to be rather costly - searching the entire
+ // output stream of a child process for multiple strings. However, it is necessary
+ // to detect this condition, a failure to map an archive, since this is not a real
+ // failure of the test or VM operation, and results in a test being "skipped".
+ // Suggestions to improve:
+ // 1. VM can designate a special exit code for such condition.
+ // 2. VM can print a single distinct string indicating failure to map an archive,
+ // instead of utilizing multiple messages.
+ // These are suggestions to improve testibility of the VM. However, implementing them
+ // could also improve usability in the field.
+ public static boolean isUnableToMap(OutputAnalyzer output) {
+ String outStr = output.getOutput();
+ if ((output.getExitValue() == 1) && (
+ outStr.contains("Unable to reserve shared space at required address") ||
+ outStr.contains("Unable to map ReadOnly shared space at required address") ||
+ outStr.contains("Unable to map ReadWrite shared space at required address") ||
+ outStr.contains("Unable to map MiscData shared space at required address") ||
+ outStr.contains("Unable to map MiscCode shared space at required address") ||
+ outStr.contains("Unable to map OptionalData shared space at required address") ||
+ outStr.contains("Could not allocate metaspace at a compatible address") ||
+ outStr.contains("UseSharedSpaces: Unable to allocate region, range is not within java heap") ))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public static Result run(String... cliPrefix) throws Exception {
+ CDSOptions opts = new CDSOptions();
+ opts.setArchiveName(getDefaultArchiveName());
+ opts.addPrefix(cliPrefix);
+ return new Result(opts, runWithArchive(opts));
+ }
+
+ public static Result run(CDSOptions opts) throws Exception {
+ return new Result(opts, runWithArchive(opts));
+ }
+
+ // Execute JVM with CDS archive, specify command line args suffix
+ public static OutputAnalyzer runWithArchive(String... cliPrefix)
+ throws Exception {
+
+ return runWithArchive( (new CDSOptions())
+ .setArchiveName(getDefaultArchiveName())
+ .addPrefix(cliPrefix) );
+ }
+
+
+ // Execute JVM with CDS archive, specify CDSOptions
+ public static OutputAnalyzer runWithArchive(CDSOptions opts)
+ throws Exception {
+
+ ArrayList<String> cmd = new ArrayList<String>();
+
+ for (String p : opts.prefix) cmd.add(p);
+
+ cmd.add("-Xshare:" + opts.xShareMode);
+ cmd.add("-Dtest.timeout.factor=" + TestTimeoutFactor);
+
+ if (opts.archiveName == null)
+ opts.archiveName = getDefaultArchiveName();
+ cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
+
+ if (opts.useVersion)
+ cmd.add("-version");
+
+ for (String s : opts.suffix) cmd.add(s);
+
+ String[] cmdLine = cmd.toArray(new String[cmd.size()]);
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
+ return executeAndLog(pb, "exec");
+ }
+
+
+ // A commonly used convenience methods to create an archive and check the results
+ // Creates an archive and checks for errors
+ public static OutputAnalyzer runWithArchiveAndCheck(CDSOptions opts) throws Exception {
+ return checkExec(runWithArchive(opts));
+ }
+
+
+ public static OutputAnalyzer runWithArchiveAndCheck(String... cliPrefix) throws Exception {
+ return checkExec(runWithArchive(cliPrefix));
+ }
+
+
+ public static OutputAnalyzer checkExec(OutputAnalyzer output,
+ String... extraMatches) throws Exception {
+ CDSOptions opts = new CDSOptions();
+ return checkExec(output, opts, extraMatches);
+ }
+
+
+ // check result of 'exec' operation, that is when JVM is run using the archive
+ public static OutputAnalyzer checkExec(OutputAnalyzer output, CDSOptions opts,
+ String... extraMatches) throws Exception {
+ try {
+ if ("on".equals(opts.xShareMode)) {
+ output.shouldContain("sharing");
+ }
+ output.shouldHaveExitValue(0);
+ } catch (RuntimeException e) {
+ checkCommonExecExceptions(output, e);
+ return output;
+ }
+
+ checkMatches(output, extraMatches);
+ return output;
+ }
+
+
+ public static OutputAnalyzer checkExecExpectError(OutputAnalyzer output,
+ int expectedExitValue,
+ String... extraMatches) throws Exception {
+ if (isUnableToMap(output)) {
+ System.out.println(UnableToMapMsg);
+ return output;
+ }
+
+ output.shouldHaveExitValue(expectedExitValue);
+ checkMatches(output, extraMatches);
+ return output;
+ }
+
+ public static OutputAnalyzer checkMatches(OutputAnalyzer output,
+ String... matches) throws Exception {
+ for (String match : matches) {
+ output.shouldContain(match);
+ }
+ return output;
+ }
+
+
+ // get the file object for the test artifact
+ public static File getTestArtifact(String name, boolean checkExistence) {
+ File dir = new File(System.getProperty("test.classes", "."));
+ File file = new File(dir, name);
+
+ if (checkExistence && !file.exists()) {
+ throw new RuntimeException("Cannot find " + file.getPath());
+ }
+
+ return file;
+ }
+
+
+ // create file containing the specified class list
+ public static File makeClassList(String classes[])
+ throws Exception {
+ return makeClassList(getTestName() + "-", classes);
+ }
+
+ // create file containing the specified class list
+ public static File makeClassList(String testCaseName, String classes[])
+ throws Exception {
+
+ File classList = getTestArtifact(testCaseName + "test.classlist", false);
+ FileOutputStream fos = new FileOutputStream(classList);
+ PrintStream ps = new PrintStream(fos);
+
+ addToClassList(ps, classes);
+
+ ps.close();
+ fos.close();
+
+ return classList;
+ }
+
+
+ public static void addToClassList(PrintStream ps, String classes[])
+ throws IOException
+ {
+ if (classes != null) {
+ for (String s : classes) {
+ ps.println(s);
+ }
+ }
+ }
+
+
+ // Optimization for getting a test name.
+ // Test name does not change during execution of the test,
+ // but getTestName() uses stack walking hence it is expensive.
+ // Therefore cache it and reuse it.
+ private static String testName;
+ public static String getTestName() {
+ if (testName == null) {
+ testName = Utils.getTestName();
+ }
+ return testName;
+ }
+
+ private static final SimpleDateFormat timeStampFormat =
+ new SimpleDateFormat("HH'h'mm'm'ss's'SSS");
+
+ private static String defaultArchiveName;
+
+ // Call this method to start new archive with new unique name
+ public static void startNewArchiveName() {
+ defaultArchiveName = getTestName() +
+ timeStampFormat.format(new Date()) + ".jsa";
+ }
+
+ public static String getDefaultArchiveName() {
+ return defaultArchiveName;
+ }
+
+
+ // ===================== FILE ACCESS convenience methods
+ public static File getOutputFile(String name) {
+ File dir = new File(System.getProperty("test.classes", "."));
+ return new File(dir, getTestName() + "-" + name);
+ }
+
+
+ public static File getOutputSourceFile(String name) {
+ File dir = new File(System.getProperty("test.classes", "."));
+ return new File(dir, name);
+ }
+
+
+ public static File getSourceFile(String name) {
+ File dir = new File(System.getProperty("test.src", "."));
+ return new File(dir, name);
+ }
+
+
+ // ============================= Logging
+ public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception {
+ long started = System.currentTimeMillis();
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+ writeFile(getOutputFile(logName + ".stdout"), output.getStdout());
+ writeFile(getOutputFile(logName + ".stderr"), output.getStderr());
+ System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
+ System.out.println("[STDERR]\n" + output.getStderr());
+
+ if (CopyChildStdoutToMainStdout)
+ System.out.println("[STDOUT]\n" + output.getStdout());
+
+ return output;
+ }
+
+
+ private static void writeFile(File file, String content) throws Exception {
+ FileOutputStream fos = new FileOutputStream(file);
+ PrintStream ps = new PrintStream(fos);
+ ps.print(content);
+ ps.close();
+ fos.close();
+ }
+}
diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/compiler/CompilerUtils.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/compiler/CompilerUtils.java
new file mode 100644
index 00000000..a02a1742
--- /dev/null
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/compiler/CompilerUtils.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.java.testlibrary.compiler;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.tools.JavaCompiler;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+/**
+ * This class consists exclusively of static utility methods for invoking the
+ * java compiler.
+ */
+public final class CompilerUtils {
+ private CompilerUtils() {
+ }
+
+ /**
+ * Compile all the java sources in {@code <source>/**} to
+ * {@code <destination>/**}. The destination directory will be created if
+ * it doesn't exist.
+ * <p>
+ * Equivalent to calling {@code compile(source, destination, true, options);}.
+ * <p>
+ * All warnings/errors emitted by the compiler are output to System.out/err.
+ *
+ * @param source Path to the source directory
+ * @param destination Path to the destination directory
+ * @param options Any options to pass to the compiler
+ * @return true if the compilation is successful
+ * @throws IOException if there is an I/O error scanning the source tree or
+ * creating the destination directory
+ * @throws UnsupportedOperationException if there is no system java compiler
+ */
+ public static boolean compile(Path source, Path destination, String... options)
+ throws IOException {
+ return compile(source, destination, true, options);
+ }
+
+ /**
+ * Compile all the java sources in {@code <source>} and optionally its
+ * subdirectories, to
+ * {@code <destination>}. The destination directory will be created if
+ * it doesn't exist.
+ * <p>
+ * All warnings/errors emitted by the compiler are output to System.out/err.
+ *
+ * @param source Path to the source directory
+ * @param destination Path to the destination directory
+ * @param recurse If {@code true} recurse into any {@code source} subdirectories
+ * to compile all java source files; else only compile those directly in
+ * {@code source}.
+ * @param options Any options to pass to the compiler
+ * @return true if the compilation is successful
+ * @throws IOException if there is an I/O error scanning the source tree or
+ * creating the destination directory
+ * @throws UnsupportedOperationException if there is no system java compiler
+ */
+
+ public static boolean compile(Path source, Path destination, boolean recurse, String... options)
+ throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ // no compiler available
+ throw new UnsupportedOperationException("Unable to get system java compiler. "
+ + "Perhaps, jdk.compiler module is not available.");
+ }
+ StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
+
+ List<File> sources
+ = Files.find(source, (recurse ? Integer.MAX_VALUE : 1),
+ (file, attrs) -> (file.toString().endsWith(".java")))
+ .map(e -> e.toFile()) // use jdk1.8
+ .collect(Collectors.toList());
+
+ Files.createDirectories(destination);
+// jfm.setLocation(StandardLocation.CLASS_PATH, Collections.emptyList()); comment out , use jdk1.8, backport from jdk11u
+ jfm.setLocation(StandardLocation.CLASS_OUTPUT,
+ Collections.singletonList(destination.toFile()));
+
+ List<String> opts = Arrays.asList(options);
+ JavaCompiler.CompilationTask task
+ = compiler.getTask(null, jfm, null, opts, null,
+ jfm.getJavaFileObjectsFromFiles(sources)); // use jdk1.8
+
+ return task.call();
+ }
+}
diff --git a/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java b/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
index 909e09f9..f06b1cbb 100644
--- a/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
+++ b/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
@@ -28,9 +28,11 @@ import java.lang.management.MemoryUsage;
import java.lang.reflect.Executable;
import java.util.Arrays;
import java.util.List;
+import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;
import java.security.BasicPermission;
+import java.util.Objects;
import java.net.URL;
import sun.hotspot.parser.DiagnosticCommand;
@@ -137,6 +139,31 @@ public class WhiteBox {
}
public native boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr);
public native boolean isMethodQueuedForCompilation(Executable method);
+
+ // Determine if the compiler corresponding to the compilation level 'compLevel'
+ // and to the compilation context 'compilation_context' provides an intrinsic
+ // for the method 'method'. An intrinsic is available for method 'method' if:
+ // - the intrinsic is enabled (by using the appropriate command-line flag) and
+ // - the platform on which the VM is running provides the instructions necessary
+ // for the compiler to generate the intrinsic code.
+ //
+ // The compilation context is related to using the DisableIntrinsic flag on a
+ // per-method level, see hotspot/src/share/vm/compiler/abstractCompiler.hpp
+ // for more details.
+ public boolean isIntrinsicAvailable(Executable method,
+ Executable compilationContext,
+ int compLevel) {
+ Objects.requireNonNull(method);
+ return isIntrinsicAvailable0(method, compilationContext, compLevel);
+ }
+ // If usage of the DisableIntrinsic flag is not expected (or the usage can be ignored),
+ // use the below method that does not require the compilation context as argument.
+ public boolean isIntrinsicAvailable(Executable method, int compLevel) {
+ return isIntrinsicAvailable(method, null, compLevel);
+ }
+ private native boolean isIntrinsicAvailable0(Executable method,
+ Executable compilationContext,
+ int compLevel);
public int deoptimizeMethod(Executable method) {
return deoptimizeMethod(method, false /*not osr*/);
}
@@ -253,5 +280,4 @@ public class WhiteBox {
// Container testing
public native boolean isContainerized();
public native void printOsInfo();
-
}
diff --git a/hotspot/test/testlibrary/whitebox/sun/hotspot/code/Compiler.java b/hotspot/test/testlibrary/whitebox/sun/hotspot/code/Compiler.java
new file mode 100644
index 00000000..bb06f1af
--- /dev/null
+++ b/hotspot/test/testlibrary/whitebox/sun/hotspot/code/Compiler.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.hotspot.code;
+
+import java.lang.reflect.Executable;
+import sun.hotspot.WhiteBox;
+
+/**
+ * API to obtain information about enabled JIT compilers
+ * retrieved from the VM with the WhiteBox API.
+ */
+public class Compiler {
+
+ private static final WhiteBox WB = WhiteBox.getWhiteBox();
+
+ /**
+ * Check if Graal is used as JIT compiler.
+ *
+ * Graal is enabled if following conditions are true:
+ * - we are not in Interpreter mode
+ * - UseJVMCICompiler flag is true
+ * - jvmci.Compiler variable is equal to 'graal'
+ * - TieredCompilation is not used or TieredStopAtLevel is greater than 3
+ * No need to check client mode because it set UseJVMCICompiler to false.
+ *
+ * @return true if Graal is used as JIT compiler.
+ */
+ public static boolean isGraalEnabled() {
+ Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
+ if (useCompiler == null || !useCompiler) {
+ return false;
+ }
+ Boolean useJvmciComp = WB.getBooleanVMFlag("UseJVMCICompiler");
+ if (useJvmciComp == null || !useJvmciComp) {
+ return false;
+ }
+ // This check might be redundant but let's keep it for now.
+ String jvmciCompiler = System.getProperty("jvmci.Compiler");
+ if (jvmciCompiler == null || !jvmciCompiler.equals("graal")) {
+ return false;
+ }
+
+ Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
+ Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");
+ // if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used
+ if (tieredCompilation != null && tieredCompilation &&
+ compLevel != null && compLevel <= 3) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Check if C2 is used as JIT compiler.
+ *
+ * C2 is enabled if following conditions are true:
+ * - we are not in Interpreter mode
+ * - we are in Server compilation mode
+ * - TieredCompilation is not used or TieredStopAtLevel is greater than 3
+ * - Graal is not used
+ *
+ * @return true if C2 is used as JIT compiler.
+ */
+ public static boolean isC2Enabled() {
+ Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
+ if (useCompiler == null || !useCompiler) {
+ return false;
+ }
+ Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");
+ if (serverMode == null || !serverMode) {
+ return false;
+ }
+
+ Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
+ Long compLevel = WB.getIntxVMFlag("TieredStopAtLevel");
+ // if TieredCompilation is enabled and compilation level is <= 3 then no Graal is used
+ if (tieredCompilation != null && tieredCompilation &&
+ compLevel != null && compLevel <= 3) {
+ return false;
+ }
+
+ if (isGraalEnabled()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /*
+ * Check if C1 is used as JIT compiler.
+ *
+ * C1 is enabled if following conditions are true:
+ * - we are not in Interpreter mode
+ * - we are not in Server compilation mode
+ * - TieredCompilation is used in Server mode
+ *
+ * @return true if C1 is used as JIT compiler.
+ */
+ public static boolean isC1Enabled() {
+ Boolean useCompiler = WB.getBooleanVMFlag("UseCompiler");
+ if (useCompiler == null || !useCompiler) {
+ return false;
+ }
+ Boolean serverMode = WB.getBooleanVMFlag("ProfileInterpreter");
+ if (serverMode == null || !serverMode) {
+ return true; // Client mode
+ }
+
+ Boolean tieredCompilation = WB.getBooleanVMFlag("TieredCompilation");
+ // C1 is not used in server mode if TieredCompilation is off.
+ if (tieredCompilation != null && !tieredCompilation) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * Determine if the compiler corresponding to the compilation level 'compLevel'
+ * provides an intrinsic for 'class'.'method'.
+ */
+ public static boolean isIntrinsicAvailable(int compLevel, String klass, String method, Class<?>... parameterTypes) {
+ Executable intrinsicMethod;
+ try {
+ intrinsicMethod = Class.forName(klass).getDeclaredMethod(method, parameterTypes);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Test bug, '" + method + "' method unavailable. " + e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Test bug, '" + klass + "' class unavailable. " + e);
+ }
+ return WB.isIntrinsicAvailable(intrinsicMethod, compLevel);
+ }
+}
+
1
https://gitee.com/kuenking111/openjdk-1.8.0.git
git@gitee.com:kuenking111/openjdk-1.8.0.git
kuenking111
openjdk-1.8.0
openjdk-1.8.0
master

搜索帮助