src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotGraalManagementTest.java
changeset 57537 ecc6e394475f
parent 52910 583fd71c47d6
child 58299 6df94ce3ab2f
equal deleted inserted replaced
57536:67cce1b84a9a 57537:ecc6e394475f
   376         assertNotNull("three args variant (as used by VisualVM) found", dumpOp);
   376         assertNotNull("three args variant (as used by VisualVM) found", dumpOp);
   377 
   377 
   378         MBeanAttributeInfo dumpPath = findAttributeInfo("DumpPath", info);
   378         MBeanAttributeInfo dumpPath = findAttributeInfo("DumpPath", info);
   379         MBeanAttributeInfo printGraphFile = findAttributeInfo("PrintGraphFile", info);
   379         MBeanAttributeInfo printGraphFile = findAttributeInfo("PrintGraphFile", info);
   380         MBeanAttributeInfo showDumpFiles = findAttributeInfo("ShowDumpFiles", info);
   380         MBeanAttributeInfo showDumpFiles = findAttributeInfo("ShowDumpFiles", info);
       
   381         MBeanAttributeInfo methodFilter = findAttributeInfo("MethodFilter", info);
   381         Object originalDumpPath = server.getAttribute(mbeanName, dumpPath.getName());
   382         Object originalDumpPath = server.getAttribute(mbeanName, dumpPath.getName());
   382         Object originalPrintGraphFile = server.getAttribute(mbeanName, printGraphFile.getName());
   383         Object originalPrintGraphFile = server.getAttribute(mbeanName, printGraphFile.getName());
   383         Object originalShowDumpFiles = server.getAttribute(mbeanName, showDumpFiles.getName());
   384         Object originalShowDumpFiles = server.getAttribute(mbeanName, showDumpFiles.getName());
       
   385         Object originalMethodFilter = server.getAttribute(mbeanName, methodFilter.getName());
   384         final File tmpDir = new File(HotSpotGraalManagementTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
   386         final File tmpDir = new File(HotSpotGraalManagementTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
   385 
   387 
   386         server.setAttribute(mbeanName, new Attribute(dumpPath.getName(), quoted(tmpDir)));
   388         server.setAttribute(mbeanName, new Attribute(dumpPath.getName(), quoted(tmpDir)));
       
   389         server.setAttribute(mbeanName, new Attribute(methodFilter.getName(), ""));
   387         // Force output to a file even if there's a running IGV instance available.
   390         // Force output to a file even if there's a running IGV instance available.
   388         server.setAttribute(mbeanName, new Attribute(printGraphFile.getName(), true));
   391         server.setAttribute(mbeanName, new Attribute(printGraphFile.getName(), true));
   389         server.setAttribute(mbeanName, new Attribute(showDumpFiles.getName(), false));
   392         server.setAttribute(mbeanName, new Attribute(showDumpFiles.getName(), false));
   390         Object[] params = {"java.util.Arrays", "asList", ":3"};
   393         Object[] params = {"java.util.Arrays", "asList", ":3"};
   391         try {
   394         try {
   392             server.invoke(mbeanName, "dumpMethod", params, null);
   395             server.invoke(mbeanName, "dumpMethod", params, null);
   393             boolean found = false;
   396             boolean found = false;
   394             String expectedIgvDumpSuffix = "[Arrays.asList(Object[])List].bgv";
   397             String expectedIgvDumpSuffix = "[Arrays.asList(Object[])List].bgv";
       
   398             Assert.assertTrue(tmpDir.toString() + " was not created or is not a directory", tmpDir.isDirectory());
   395             List<String> dumpPathEntries = Arrays.asList(tmpDir.list());
   399             List<String> dumpPathEntries = Arrays.asList(tmpDir.list());
   396             for (String entry : dumpPathEntries) {
   400             for (String entry : dumpPathEntries) {
   397                 if (entry.endsWith(expectedIgvDumpSuffix)) {
   401                 if (entry.endsWith(expectedIgvDumpSuffix)) {
   398                     found = true;
   402                     found = true;
   399                 }
   403                 }
   401             if (!found) {
   405             if (!found) {
   402                 Assert.fail(String.format("Expected file ending with \"%s\" in %s but only found:%n%s", expectedIgvDumpSuffix, tmpDir,
   406                 Assert.fail(String.format("Expected file ending with \"%s\" in %s but only found:%n%s", expectedIgvDumpSuffix, tmpDir,
   403                                 dumpPathEntries.stream().collect(Collectors.joining(System.lineSeparator()))));
   407                                 dumpPathEntries.stream().collect(Collectors.joining(System.lineSeparator()))));
   404             }
   408             }
   405         } finally {
   409         } finally {
   406             deleteDirectory(tmpDir.toPath());
   410             if (tmpDir.isDirectory()) {
       
   411                 deleteDirectory(tmpDir.toPath());
       
   412             }
   407             server.setAttribute(mbeanName, new Attribute(dumpPath.getName(), originalDumpPath));
   413             server.setAttribute(mbeanName, new Attribute(dumpPath.getName(), originalDumpPath));
       
   414             server.setAttribute(mbeanName, new Attribute(methodFilter.getName(), originalMethodFilter));
   408             server.setAttribute(mbeanName, new Attribute(printGraphFile.getName(), originalPrintGraphFile));
   415             server.setAttribute(mbeanName, new Attribute(printGraphFile.getName(), originalPrintGraphFile));
   409             server.setAttribute(mbeanName, new Attribute(showDumpFiles.getName(), originalShowDumpFiles));
   416             server.setAttribute(mbeanName, new Attribute(showDumpFiles.getName(), originalShowDumpFiles));
   410         }
   417         }
   411     }
   418     }
   412 
   419