test/serviceability/jdwp/AllModulesCommandTest.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
bug_8166312 Cdiff test/serviceability/jdwp/AllModulesCommandTest.java
test/serviceability/jdwp/AllModulesCommandTest.java
Print this page
*** 28,38 ****
import java.util.HashSet;
import static jdk.test.lib.Asserts.assertTrue;
/**
* @test
! * @summary Tests the modules-related JDWP commands
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @compile AllModulesCommandTestDebuggee.java
* @run main/othervm AllModulesCommandTest
*/
--- 28,38 ----
import java.util.HashSet;
import static jdk.test.lib.Asserts.assertTrue;
/**
* @test
! * @summary Tests AllModules JDWP command
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @compile AllModulesCommandTestDebuggee.java
* @run main/othervm AllModulesCommandTest
*/
*** 86,100 ****
JdwpAllModulesReply reply = new JdwpAllModulesCmd().send(channel);
assertReply(reply);
for (int i = 0; i < reply.getModulesCount(); ++i) {
long modId = reply.getModuleId(i);
// For each module reported by JDWP get its name using the JDWP NAME command
! // and store the reply
! String modName = getModuleName(modId);
! if (modName != null) { // JDWP reports unnamed modules, ignore them
! jdwpModuleNames.add(modName);
! }
// Assert the JDWP CANREAD and CLASSLOADER commands
assertCanRead(modId);
assertClassLoader(modId);
}
--- 86,96 ----
JdwpAllModulesReply reply = new JdwpAllModulesCmd().send(channel);
assertReply(reply);
for (int i = 0; i < reply.getModulesCount(); ++i) {
long modId = reply.getModuleId(i);
// For each module reported by JDWP get its name using the JDWP NAME command
! getModuleName(modId);
// Assert the JDWP CANREAD and CLASSLOADER commands
assertCanRead(modId);
assertClassLoader(modId);
}
*** 116,129 ****
} catch (Exception x) {
}
}
}
! private String getModuleName(long modId) throws IOException {
JdwpModNameReply reply = new JdwpModNameCmd(modId).send(channel);
assertReply(reply);
! return reply.getModuleName();
}
private void assertReply(JdwpReply reply) {
// Simple assert for any JDWP reply
if (reply.getErrorCode() != 0) {
--- 112,129 ----
} catch (Exception x) {
}
}
}
! private void getModuleName(long modId) throws IOException {
! // Send out the JDWP NAME command and store the reply
JdwpModNameReply reply = new JdwpModNameCmd(modId).send(channel);
assertReply(reply);
! String modName = reply.getModuleName();
! if (modName != null) { // JDWP reports unnamed modules, ignore them
! jdwpModuleNames.add(modName);
! }
}
private void assertReply(JdwpReply reply) {
// Simple assert for any JDWP reply
if (reply.getErrorCode() != 0) {
*** 137,177 ****
assertReply(reply);
assertTrue(reply.canRead(), "canRead() reports false for reading from the same module");
}
private void assertClassLoader(long modId) throws IOException {
! // Verify that the module classloader id is valid
JdwpClassLoaderReply reply = new JdwpClassLoaderCmd(modId).send(channel);
assertReply(reply);
! long moduleClassLoader = reply.getClassLoaderId();
! assertTrue(moduleClassLoader >= 0, "bad classloader refId " + moduleClassLoader + " for module id " + modId);
!
! String clsModName = getModuleName(modId);
! if ("java.base".equals(clsModName)) {
! // For the java.base module, because there will be some loaded classes, we can verify
! // that some of the loaded classes do report the java.base module as the module they belong to
! assertGetModule(moduleClassLoader, modId);
! }
! }
!
! private void assertGetModule(long moduleClassLoader, long modId) throws IOException {
! // Get all the visible classes for the module classloader
! JdwpVisibleClassesReply visibleClasses = new JdwpVisibleClassesCmd(moduleClassLoader).send(channel);
! assertReply(visibleClasses);
!
! boolean moduleFound = false;
! for (long clsId : visibleClasses.getVisibleClasses()) {
! // For each visible class get the module the class belongs to
! JdwpModuleReply modReply = new JdwpModuleCmd(clsId).send(channel);
! assertReply(modReply);
! long clsModId = modReply.getModuleId();
!
! // At least one of the visible classes should belong to our module
! if (modId == clsModId) {
! moduleFound = true;
! break;
! }
! }
! assertTrue(moduleFound, "None of the visible classes for the classloader of the module " + getModuleName(modId) + " reports the module as its own");
}
}
--- 137,149 ----
assertReply(reply);
assertTrue(reply.canRead(), "canRead() reports false for reading from the same module");
}
private void assertClassLoader(long modId) throws IOException {
! // Simple assert for the CLASSLOADER command
JdwpClassLoaderReply reply = new JdwpClassLoaderCmd(modId).send(channel);
assertReply(reply);
! long clId = reply.getClassLoaderId();
! assertTrue(clId >= 0, "bad classloader refId " + clId + " for module id " + modId);
}
}
test/serviceability/jdwp/AllModulesCommandTest.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File