103
104 String agentCmdArg, flagFile;
105 if (attachAgent) {
106 // we will attach the agent, so don't specify -javaagent in the command line. We'll use
107 // something harmless like -showversion to make it easier to construct the command line
108 agentCmdArg = "-showversion";
109 } else {
110 agentCmdArg = "-javaagent:" + agentJar;
111 }
112
113 // First, run the test class directly, w/o sharing, as a baseline reference
114 flagFile = getFlagFile(attachAgent);
115 AgentAttachThread t = doAttach(attachAgent, flagFile, agentJar);
116 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
117 bootCP,
118 "-cp", appJar,
119 "-XX:+UnlockDiagnosticVMOptions",
120 "-XX:+WhiteBoxAPI",
121 "-Xshare:off",
122 agentCmdArg,
123 "InstrumentationApp", bootJar, appJar, custJar, flagFile);
124 TestCommon.executeAndLog(pb, "no-sharing").shouldHaveExitValue(0);
125 checkAttach(t);
126
127 // Dump the AppCDS archive. On some platforms AppCDSv2 may not be enabled, so we
128 // first try the v2 classlist, and if that fails, revert to the v1 classlist.
129 // Note that the InstrumentationApp$ArchivedIfAppCDSv2Enabled class is archived
130 // only if V2 is enabled. This is tested by InstrumentationApp.isAppCDSV2Enabled().
131 String[] v2Classes = {
132 "InstrumentationApp$ArchivedIfAppCDSv2Enabled",
133 "java/lang/Object id: 0",
134 "InstrumentationApp$Intf id: 1",
135 "InstrumentationApp$Coo id: 2 super: 0 interfaces: 1 source: " + custJar,
136 };
137 String[] sharedClassesWithV2 = TestCommon.concat(v2Classes, sharedClasses);
138 OutputAnalyzer out = TestCommon.dump(appJar, sharedClassesWithV2, bootCP);
139 if (out.getExitValue() != 0) {
140 System.out.println("Redumping with AppCDSv2 disabled");
141 TestCommon.testDump(appJar, sharedClasses, bootCP);
142 }
143
144 // Run with AppCDS.
145 System.out.println("");
146 System.out.println("============================================================");
147 System.out.println("CDS: YES, attachAgent: " + (attachAgent ? "YES" : "NO"));
148 System.out.println("============================================================");
149 System.out.println("");
150
151 flagFile = getFlagFile(attachAgent);
152 t = doAttach(attachAgent, flagFile, agentJar);
153 out = TestCommon.execAuto("-cp", appJar,
154 bootCP,
155 "-XX:+UnlockDiagnosticVMOptions",
156 "-XX:+WhiteBoxAPI",
157 agentCmdArg,
158 "InstrumentationApp", bootJar, appJar, custJar, flagFile);
159
160 CDSOptions opts = (new CDSOptions()).setXShareMode("auto");
161 TestCommon.checkExec(out, opts);
162 checkAttach(t);
163 }
164
165 static int flagFileSerial = 1;
166 static private String getFlagFile(boolean attachAgent) {
167 if (attachAgent) {
168 // Do not reuse the same file name as Windows may fail to
169 // delete the file.
170 return "attach.flag." + ProcessHandle.current().pid() +
171 "." + (flagFileSerial++) + "." + System.currentTimeMillis();
172 } else {
173 return "noattach";
174 }
175 }
176
177 static AgentAttachThread doAttach(boolean attachAgent, String flagFile, String agentJar) throws Throwable {
178 if (!attachAgent) {
|
103
104 String agentCmdArg, flagFile;
105 if (attachAgent) {
106 // we will attach the agent, so don't specify -javaagent in the command line. We'll use
107 // something harmless like -showversion to make it easier to construct the command line
108 agentCmdArg = "-showversion";
109 } else {
110 agentCmdArg = "-javaagent:" + agentJar;
111 }
112
113 // First, run the test class directly, w/o sharing, as a baseline reference
114 flagFile = getFlagFile(attachAgent);
115 AgentAttachThread t = doAttach(attachAgent, flagFile, agentJar);
116 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
117 bootCP,
118 "-cp", appJar,
119 "-XX:+UnlockDiagnosticVMOptions",
120 "-XX:+WhiteBoxAPI",
121 "-Xshare:off",
122 agentCmdArg,
123 "InstrumentationApp", flagFile, bootJar, appJar, custJar);
124 TestCommon.executeAndLog(pb, "no-sharing").shouldHaveExitValue(0);
125 checkAttach(t);
126
127 // Dump the AppCDS archive. On some platforms AppCDSv2 may not be enabled, so we
128 // first try the v2 classlist, and if that fails, revert to the v1 classlist.
129 // Note that the InstrumentationApp$ArchivedIfAppCDSv2Enabled class is archived
130 // only if V2 is enabled. This is tested by InstrumentationApp.isAppCDSV2Enabled().
131 String[] v2Classes = {
132 "InstrumentationApp$ArchivedIfAppCDSv2Enabled",
133 "java/lang/Object id: 0",
134 "InstrumentationApp$Intf id: 1",
135 "InstrumentationApp$Coo id: 2 super: 0 interfaces: 1 source: " + custJar,
136 };
137 String[] sharedClassesWithV2 = TestCommon.concat(v2Classes, sharedClasses);
138 OutputAnalyzer out = TestCommon.dump(appJar, sharedClassesWithV2, bootCP);
139 if (out.getExitValue() != 0) {
140 System.out.println("Redumping with AppCDSv2 disabled");
141 TestCommon.testDump(appJar, sharedClasses, bootCP);
142 }
143
144 // Run with AppCDS.
145 System.out.println("");
146 System.out.println("============================================================");
147 System.out.println("CDS: YES, attachAgent: " + (attachAgent ? "YES" : "NO"));
148 System.out.println("============================================================");
149 System.out.println("");
150
151 flagFile = getFlagFile(attachAgent);
152 t = doAttach(attachAgent, flagFile, agentJar);
153 out = TestCommon.execAuto("-cp", appJar,
154 bootCP,
155 "-XX:+UnlockDiagnosticVMOptions",
156 "-XX:+WhiteBoxAPI",
157 agentCmdArg,
158 "InstrumentationApp", flagFile, bootJar, appJar, custJar);
159
160 CDSOptions opts = (new CDSOptions()).setXShareMode("auto");
161 TestCommon.checkExec(out, opts);
162 checkAttach(t);
163 }
164
165 static int flagFileSerial = 1;
166 static private String getFlagFile(boolean attachAgent) {
167 if (attachAgent) {
168 // Do not reuse the same file name as Windows may fail to
169 // delete the file.
170 return "attach.flag." + ProcessHandle.current().pid() +
171 "." + (flagFileSerial++) + "." + System.currentTimeMillis();
172 } else {
173 return "noattach";
174 }
175 }
176
177 static AgentAttachThread doAttach(boolean attachAgent, String flagFile, String agentJar) throws Throwable {
178 if (!attachAgent) {
|