1 /* |
|
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 import sun.hotspot.WhiteBox; |
|
26 |
|
27 // This class should be loaded from a shared archive. |
|
28 public class MultiProcClass { |
|
29 private static String instanceLabel; |
|
30 |
|
31 public static void main(String args[]) throws Exception { |
|
32 instanceLabel = args[0]; |
|
33 String checkPmap = args[1]; |
|
34 |
|
35 long pid = ProcessHandle.current().pid(); |
|
36 System.out.println(inst("========================== Starting MultiProcClass")); |
|
37 System.out.println(inst("My PID: " + pid )); |
|
38 System.out.println(inst("checkPmap = <" + checkPmap + ">" )); |
|
39 |
|
40 if ("true".equals(checkPmap)) { |
|
41 if (runPmap(pid, true) != 0) |
|
42 System.out.println("MultiProcClass: Pmap failed"); |
|
43 } |
|
44 |
|
45 WhiteBox wb = WhiteBox.getWhiteBox(); |
|
46 if (!wb.isSharedClass(MultiProcClass.class)) { |
|
47 throw new RuntimeException(inst("MultiProcClass should be shared but is not.")); |
|
48 } |
|
49 |
|
50 System.out.println(inst("========================== Leaving MultiProcClass")); |
|
51 } |
|
52 |
|
53 // A convenience method to append process instance label |
|
54 private static String inst(String msg) { |
|
55 return "process-" + instanceLabel + " : " + msg; |
|
56 } |
|
57 |
|
58 // Use on Linux-only; requires jdk-9 for Process.pid() |
|
59 public static int runPmap(long pid, boolean inheritIO) throws Exception { |
|
60 ProcessBuilder pmapPb = new ProcessBuilder("pmap", "" + pid); |
|
61 if (inheritIO) |
|
62 pmapPb.inheritIO(); |
|
63 |
|
64 return pmapPb.start().waitFor(); |
|
65 } |
|
66 } |
|