< prev index next >

test/hotspot/jtreg/serviceability/dcmd/vm/ClassLoaderHierarchyTest.java

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com
rev 58568 : [mq]: hidden-class-4


  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Test of diagnostic command VM.classloaders
  28  * @library /test/lib
  29  * @modules java.base/jdk.internal.misc
  30  *          java.compiler
  31  *          java.management
  32  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  33  * @run testng ClassLoaderHierarchyTest
  34  */
  35 
  36 import org.testng.Assert;
  37 import org.testng.annotations.Test;
  38 
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 import jdk.test.lib.dcmd.CommandExecutor;
  41 import jdk.test.lib.dcmd.JMXExecutor;
  42 
  43 import java.io.File;
  44 import java.io.FileInputStream;
  45 import java.io.IOException;
  46 import java.nio.ByteBuffer;
  47 import java.nio.channels.FileChannel;
  48 
  49 public class ClassLoaderHierarchyTest {
  50 
  51 //+-- <bootstrap>


  80         Class<?> c3 = Class.forName("TestClass2", true, named_child_cl);
  81         if (c3.getClassLoader() != named_child_cl) {
  82             Assert.fail("TestClass defined by wrong classloader: " + c3.getClassLoader());
  83         }
  84 
  85         // First test: simple output, no classes displayed
  86         OutputAnalyzer output = executor.execute("VM.classloaders");
  87         output.shouldContain("<bootstrap>");
  88         output.shouldMatch(".*TestClassLoader");
  89         output.shouldMatch("Kevin.*TestClassLoader");
  90         output.shouldMatch("Bill.*TestClassLoader");
  91 
  92         // Second test: print with classes.
  93         output = executor.execute("VM.classloaders show-classes");
  94         output.shouldContain("<bootstrap>");
  95         output.shouldContain("java.lang.Object");
  96         output.shouldMatch(".*TestClassLoader");
  97         output.shouldMatch("Kevin.*TestClassLoader");
  98         output.shouldMatch("Bill.*TestClassLoader");
  99         output.shouldContain("TestClass2");
 100         output.shouldContain("Weak Hidden Classes:");
 101     }
 102 
 103     static class TestClassLoader extends ClassLoader {
 104 
 105         public TestClassLoader() {
 106             super();
 107         }
 108 
 109         public TestClassLoader(String name, ClassLoader parent) {
 110             super(name, parent);
 111         }
 112 
 113         public static final String CLASS_NAME = "TestClass2";
 114 
 115         static ByteBuffer readClassFile(String name)
 116         {
 117             File f = new File(System.getProperty("test.classes", "."),
 118                               name);
 119             try (FileInputStream fin = new FileInputStream(f);
 120                  FileChannel fc = fin.getChannel())




  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Test of diagnostic command VM.classloaders
  28  * @library /test/lib
  29  * @modules java.base/jdk.internal.misc
  30  *          jdk.compiler

  31  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  32  * @run testng ClassLoaderHierarchyTest
  33  */
  34 
  35 import org.testng.Assert;
  36 import org.testng.annotations.Test;
  37 
  38 import jdk.test.lib.process.OutputAnalyzer;
  39 import jdk.test.lib.dcmd.CommandExecutor;
  40 import jdk.test.lib.dcmd.JMXExecutor;
  41 
  42 import java.io.File;
  43 import java.io.FileInputStream;
  44 import java.io.IOException;
  45 import java.nio.ByteBuffer;
  46 import java.nio.channels.FileChannel;
  47 
  48 public class ClassLoaderHierarchyTest {
  49 
  50 //+-- <bootstrap>


  79         Class<?> c3 = Class.forName("TestClass2", true, named_child_cl);
  80         if (c3.getClassLoader() != named_child_cl) {
  81             Assert.fail("TestClass defined by wrong classloader: " + c3.getClassLoader());
  82         }
  83 
  84         // First test: simple output, no classes displayed
  85         OutputAnalyzer output = executor.execute("VM.classloaders");
  86         output.shouldContain("<bootstrap>");
  87         output.shouldMatch(".*TestClassLoader");
  88         output.shouldMatch("Kevin.*TestClassLoader");
  89         output.shouldMatch("Bill.*TestClassLoader");
  90 
  91         // Second test: print with classes.
  92         output = executor.execute("VM.classloaders show-classes");
  93         output.shouldContain("<bootstrap>");
  94         output.shouldContain("java.lang.Object");
  95         output.shouldMatch(".*TestClassLoader");
  96         output.shouldMatch("Kevin.*TestClassLoader");
  97         output.shouldMatch("Bill.*TestClassLoader");
  98         output.shouldContain("TestClass2");
  99         output.shouldContain("Hidden Classes:");
 100     }
 101 
 102     static class TestClassLoader extends ClassLoader {
 103 
 104         public TestClassLoader() {
 105             super();
 106         }
 107 
 108         public TestClassLoader(String name, ClassLoader parent) {
 109             super(name, parent);
 110         }
 111 
 112         public static final String CLASS_NAME = "TestClass2";
 113 
 114         static ByteBuffer readClassFile(String name)
 115         {
 116             File f = new File(System.getProperty("test.classes", "."),
 117                               name);
 118             try (FileInputStream fin = new FileInputStream(f);
 119                  FileChannel fc = fin.getChannel())


< prev index next >