|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -94,6 +94,98 @@ public static void main(String[] args) throws Exception {
|
94 | 94 | expStrMap.put(cmd, List.of(tokensMap.get(key)));
|
95 | 95 | test.run(theApp.getPid(), cmds, expStrMap, null);
|
96 | 96 | }
|
| 97 | + |
| 98 | + // This part is testing JDK-8261269. When inspecting a java object, we want to make |
| 99 | + // sure the address is not printed twice and that "Oop for ..." is not printed twice. |
| 100 | + // |
| 101 | + // The goal of this test is to dump the Class instance for java.lang.System. It contains |
| 102 | + // some Oop statics, and that's where the redundant "Oop for..." was noticed. The script |
| 103 | + // looks something like this: |
| 104 | + // |
| 105 | + // hsdb> class java.lang.System |
| 106 | + // java/lang/System @0x000000080000f388 |
| 107 | + // |
| 108 | + // hsdb> inspect 0x000000080000f388 |
| 109 | + // Type is InstanceKlass (size of 480) |
| 110 | + // ... |
| 111 | + // OopHandle Klass::_java_mirror: OopHandle @ 0x000000080000f400 |
| 112 | + // ... |
| 113 | + // |
| 114 | + // hsdb> examine 0x000000080000f400 |
| 115 | + // 0x000000080000f400: 0x00007fd8b812e5e8 |
| 116 | + // |
| 117 | + // hsdb> examine 0x00007fd8b812e5e8 |
| 118 | + // 0x00007fd8b812e5e8: 0x00000007fef00770 |
| 119 | + // |
| 120 | + // hsdb> inspect 0x00000007fef00770 |
| 121 | + // instance of Oop for java/lang/Class @ 0x00000007fef00770 @ 0x00000007fef00770 (size = 160) |
| 122 | + // in: Oop for java/io/BufferedInputStream @ 0x0000000082005b08 Oop for java/io/BufferedInputStream @ 0x0000000082005b08 |
| 123 | + // out: Oop for java/io/PrintStream @ 0x0000000082007b60 Oop for java/io/PrintStream @ 0x0000000082007b60 |
| 124 | + // err: Oop for java/io/PrintStream @ 0x000000008200e0c8 Oop for java/io/PrintStream @ 0x000000008200e0c8 |
| 125 | + |
| 126 | + String cmd; |
| 127 | + Map<String, List<String>> expStrMap; |
| 128 | + Map<String, List<String>> unexpStrMap; |
| 129 | + |
| 130 | + // Start with the "class java.lang.System" |
| 131 | + cmd = "class java.lang.System"; |
| 132 | + cmds = List.of(cmd); |
| 133 | + expStrMap = new HashMap<>(); |
| 134 | + expStrMap.put(cmd, List.of("java.lang.System @0x")); |
| 135 | + String classCmdOutput = test.run(theApp.getPid(), cmds, expStrMap, null); |
| 136 | + |
| 137 | + // "inspect" the address produced by the "class java.lang.System". This is the InstanceKlass. |
| 138 | + String classAddress = classCmdOutput.substring(classCmdOutput.indexOf("@0x")+1); |
| 139 | + lines = classAddress.split("\\R"); |
| 140 | + classAddress = lines[0]; |
| 141 | + cmd = "inspect " + classAddress; |
| 142 | + cmds = List.of(cmd); |
| 143 | + expStrMap = new HashMap<>(); |
| 144 | + expStrMap.put(cmd, List.of("Type is InstanceKlass", "Klass::_java_mirror: OopHandle @")); |
| 145 | + String inspectCmdOutput = test.run(theApp.getPid(), cmds, expStrMap, null); |
| 146 | + |
| 147 | + // Get the Klass::_java_mirror value from the InstanceKlass |
| 148 | + String mirrorPattern = "Klass::_java_mirror: OopHandle @ "; |
| 149 | + String mirrorAddress = inspectCmdOutput.substring( |
| 150 | + inspectCmdOutput.indexOf(mirrorPattern) + mirrorPattern.length()); |
| 151 | + lines = mirrorAddress.split("\\R"); |
| 152 | + mirrorAddress = lines[0]; |
| 153 | + |
| 154 | + // Use "examine" to do an indirection of the _java_mirror. |
| 155 | + cmd = "examine " + mirrorAddress; |
| 156 | + cmds = List.of(cmd); |
| 157 | + expStrMap = new HashMap<>(); |
| 158 | + expStrMap.put(cmd, List.of(mirrorAddress + ": 0x")); |
| 159 | + String examineCmdOutput = test.run(theApp.getPid(), cmds, expStrMap, null); |
| 160 | + String examineResult = examineCmdOutput.substring(examineCmdOutput.indexOf(": 0x")+2); |
| 161 | + lines = examineResult.split("\\R"); |
| 162 | + examineResult = lines[0].trim(); // examine leaves a trailing space |
| 163 | + |
| 164 | + // Do another indirection using "examine" to get to the address of the Class instance. |
| 165 | + cmd = "examine " + examineResult; |
| 166 | + cmds = List.of(cmd); |
| 167 | + expStrMap = new HashMap<>(); |
| 168 | + expStrMap.put(cmd, List.of(examineResult + ": 0x")); |
| 169 | + examineCmdOutput = test.run(theApp.getPid(), cmds, expStrMap, null); |
| 170 | + examineResult = examineCmdOutput.substring(examineCmdOutput.indexOf(": 0x")+2); |
| 171 | + lines = examineResult.split("\\R"); |
| 172 | + examineResult = lines[0].trim(); // examine leaves a trailing space |
| 173 | + |
| 174 | + // inspect the Class instance |
| 175 | + String instanceOfString = "instance of Oop for java/lang/Class @ "; |
| 176 | + String staticFieldString = "Oop for java/io/BufferedInputStream @"; |
| 177 | + cmd = "inspect " + examineResult; |
| 178 | + cmds = List.of(cmd); |
| 179 | + expStrMap = new HashMap<>(); |
| 180 | + expStrMap.put(cmd, List.of(instanceOfString + examineResult, |
| 181 | + "in: " + staticFieldString)); |
| 182 | + unexpStrMap = new HashMap<>(); |
| 183 | + // Make sure we don't see the address of the class intance twice, and make sure |
| 184 | + // we don't see "Oop for ..." twice for the "in" static field. |
| 185 | + unexpStrMap.put(cmd, List.of( |
| 186 | + instanceOfString + examineResult + " @ " + examineResult, |
| 187 | + "in: " + staticFieldString + " .* " + staticFieldString)); |
| 188 | + inspectCmdOutput = test.run(theApp.getPid(), cmds, expStrMap, unexpStrMap); |
97 | 189 | } catch (SkippedException e) {
|
98 | 190 | throw e;
|
99 | 191 | } catch (Exception ex) {
|
|
0 commit comments