8162504: TestInstanceKlassSize.java and TestInstanceKlassSizeForInterface.java fail on Mac OS
Summary: Modify TestInstanceKlassSizeForInterface.java to avoid the error prone mechanism of spawning a process and attaching back to the current process. Use LingeredApp instead.
Reviewed-by: dsamersoff, sspitsyn
Contributed-by: jini.george@oracle.com
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/serviceability/sa/LingeredAppWithInterface.java Thu Feb 23 12:19:03 2017 +0530
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+import jdk.test.lib.apps.LingeredApp;
+
+interface Language {
+ static final long nbrOfWords = 99999;
+ public abstract long getNbrOfWords();
+}
+
+class ParselTongue implements Language {
+ public long getNbrOfWords() {
+ return nbrOfWords * 4;
+ }
+}
+
+public class LingeredAppWithInterface extends LingeredApp {
+
+ public static void main(String args[]) {
+ ParselTongue lang = new ParselTongue();
+ Language muggleSpeak = new Language() {
+ public long getNbrOfWords() {
+ return nbrOfWords * 8;
+ }
+ };
+
+ // Not tested at this point. The test needs to be enhanced
+ // later to test for the sizes of the Lambda MetaFactory
+ // generated anonymous classes too. (After JDK-8160228 gets
+ // fixed.)
+ Runnable r2 = () -> System.out.println("Hello world!");
+ r2.run();
+
+ System.out.println(lang.getNbrOfWords() + muggleSpeak.getNbrOfWords());
+
+ LingeredApp.main(args);
+ }
+}
--- a/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java Wed Feb 22 11:20:12 2017 -0600
+++ b/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java Thu Feb 23 12:19:03 2017 +0530
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -21,11 +21,15 @@
* questions.
*/
+import java.util.ArrayList;
+import java.util.List;
+
import sun.jvm.hotspot.HotSpotAgent;
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.debugger.*;
+import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
@@ -45,29 +49,20 @@
* @run main/othervm TestInstanceKlassSizeForInterface
*/
-interface Language {
- static final long nbrOfWords = 99999;
- public abstract long getNbrOfWords();
-}
-
-class ParselTongue implements Language {
- public long getNbrOfWords() {
- return nbrOfWords * 4;
- }
-}
-
public class TestInstanceKlassSizeForInterface {
- private static void SAInstanceKlassSize(int pid,
+ private static LingeredAppWithInterface theApp = null;
+
+ private static void SAInstanceKlassSize(int lingeredAppPid,
String[] instanceKlassNames) {
HotSpotAgent agent = new HotSpotAgent();
try {
- agent.attach((int)pid);
+ agent.attach(lingeredAppPid);
}
catch (DebuggerException e) {
System.out.println(e.getMessage());
- System.err.println("Unable to connect to process ID: " + pid);
+ System.err.println("Unable to connect to process ID: " + lingeredAppPid);
agent.detach();
e.printStackTrace();
@@ -98,11 +93,9 @@
}
private static void createAnotherToAttach(
- String[] instanceKlassNames) throws Exception {
+ String[] instanceKlassNames,
+ int lingeredAppPid) throws Exception {
- ProcessBuilder pb = new ProcessBuilder();
-
- // Grab the pid from the current java process and pass it
String[] toolArgs = {
"--add-modules=jdk.hotspot.agent",
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
@@ -110,23 +103,26 @@
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED",
"TestInstanceKlassSizeForInterface",
- Long.toString(ProcessTools.getProcessId())
+ Integer.toString(lingeredAppPid)
};
+ // Start a new process to attach to the LingeredApp process
+ ProcessBuilder processBuilder = ProcessTools
+ .createJavaProcessBuilder(toolArgs);
+ OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
+ SAOutput.shouldHaveExitValue(0);
+ System.out.println(SAOutput.getOutput());
+
+ // Run jcmd on the LingeredApp process
+ ProcessBuilder pb = new ProcessBuilder();
pb.command(new String[] {
JDKToolFinder.getJDKTool("jcmd"),
- Long.toString(ProcessTools.getProcessId()),
+ Long.toString(lingeredAppPid),
"GC.class_stats",
"VTab,ITab,OopMap,KlassBytes"
}
);
- // Start a new process to attach to the current process
- ProcessBuilder processBuilder = ProcessTools
- .createJavaProcessBuilder(toolArgs);
- OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
- System.out.println(SAOutput.getOutput());
-
OutputAnalyzer jcmdOutput = new OutputAnalyzer(pb.start());
System.out.println(jcmdOutput.getOutput());
@@ -153,7 +149,7 @@
String[] instanceKlassNames = new String[] {
"Language",
"ParselTongue",
- "TestInstanceKlassSizeForInterface$1"
+ "LingeredAppWithInterface$1"
};
if (!Platform.shouldSAAttach()) {
@@ -163,22 +159,17 @@
}
if (args == null || args.length == 0) {
- ParselTongue lang = new ParselTongue();
-
- Language ventro = new Language() {
- public long getNbrOfWords() {
- return nbrOfWords * 8;
- }
- };
+ try {
+ List<String> vmArgs = new ArrayList<String>();
+ vmArgs.addAll(Utils.getVmOptions());
- // Not tested at this point. The test needs to be enhanced
- // later to test for the sizes of the Lambda MetaFactory
- // generated anonymous classes too. (After JDK-8160228 gets
- // fixed.)
- Runnable r2 = () -> System.out.println("Hello world!");
- r2.run();
-
- createAnotherToAttach(instanceKlassNames);
+ theApp = new LingeredAppWithInterface();
+ LingeredApp.startApp(vmArgs, theApp);
+ createAnotherToAttach(instanceKlassNames,
+ (int)theApp.getPid());
+ } finally {
+ LingeredApp.stopApp(theApp);
+ }
} else {
SAInstanceKlassSize(Integer.parseInt(args[0]), instanceKlassNames);
}