1 /*
2 * Copyright (c) 2017, 2022, 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 */
45 LingeredAppWithLock theApp = null;
46 try {
47 ClhsdbLauncher test = new ClhsdbLauncher();
48
49 theApp = new LingeredAppWithLock();
50 LingeredApp.startApp(theApp);
51 System.out.println("Started LingeredApp with pid " + theApp.getPid());
52
53 // Run the 'jstack -v' command to get the address of a Method*,
54 // the oop address of a java.lang.ref.ReferenceQueue$Lock
55 // and the oop address of a java.lang.Class object
56 List<String> cmds = List.of("jstack -v");
57
58 String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
59
60 // the key is a literal, searched in the jstack output; the value is a regex searched in the clhsdb output
61 Map<String, String> tokensMap = new HashMap<>();
62 tokensMap.put("(a java.lang.Class for LingeredAppWithLock)",
63 "instance of Oop for java/lang/Class");
64 tokensMap.put("Method*=", "Type is Method");
65 tokensMap.put("(a java/util/concurrent/locks/AbstractQueuedSynchronizer$ConditionObject)",
66 "instance of Oop for java/util/concurrent/locks/AbstractQueuedSynchronizer\\$ConditionObject");
67
68 String[] lines = jstackOutput.split("\\R");
69
70 for (String key: tokensMap.keySet()) {
71 cmds = new ArrayList<String>();
72 Map<String, List<String>> expStrMap = new HashMap<>();
73
74 String addressString = null;
75 for (String line : lines) {
76 if (line.contains(key)) {
77 // Escape the token "Method*=" because the split method uses
78 // a regex, not just a straight String.
79 String escapedKey = key.replace("*","\\*");
80 String[] words = line.split(escapedKey+"|[ ]");
81 for (String word : words) {
82 word = word.replace("<","").replace(">","");
83 if (word.startsWith("0x")) {
84 addressString = word;
85 break;
86 }
|
1 /*
2 * Copyright (c) 2017, 2024, 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 */
45 LingeredAppWithLock theApp = null;
46 try {
47 ClhsdbLauncher test = new ClhsdbLauncher();
48
49 theApp = new LingeredAppWithLock();
50 LingeredApp.startApp(theApp);
51 System.out.println("Started LingeredApp with pid " + theApp.getPid());
52
53 // Run the 'jstack -v' command to get the address of a Method*,
54 // the oop address of a java.lang.ref.ReferenceQueue$Lock
55 // and the oop address of a java.lang.Class object
56 List<String> cmds = List.of("jstack -v");
57
58 String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
59
60 // the key is a literal, searched in the jstack output; the value is a regex searched in the clhsdb output
61 Map<String, String> tokensMap = new HashMap<>();
62 tokensMap.put("(a java.lang.Class for LingeredAppWithLock)",
63 "instance of Oop for java/lang/Class");
64 tokensMap.put("Method*=", "Type is Method");
65 tokensMap.put("(a java.lang.ref.ReferenceQueue$Lock)",
66 "instance of Oop for java/lang/ref/ReferenceQueue\\$Lock");
67
68 String[] lines = jstackOutput.split("\\R");
69
70 for (String key: tokensMap.keySet()) {
71 cmds = new ArrayList<String>();
72 Map<String, List<String>> expStrMap = new HashMap<>();
73
74 String addressString = null;
75 for (String line : lines) {
76 if (line.contains(key)) {
77 // Escape the token "Method*=" because the split method uses
78 // a regex, not just a straight String.
79 String escapedKey = key.replace("*","\\*");
80 String[] words = line.split(escapedKey+"|[ ]");
81 for (String word : words) {
82 word = word.replace("<","").replace(">","");
83 if (word.startsWith("0x")) {
84 addressString = word;
85 break;
86 }
|