< prev index next >

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

Print this page
rev 50565 : [mq]: 8203343-VM.metaspace-show-reflection-invocation-targets
rev 50566 : [mq]: 8203343-VM.metaspace-show-reflection-invocation-targets-delta


  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 import java.lang.reflect.Constructor;
  26 import java.lang.reflect.Method;
  27 
  28 import org.testng.Assert;
  29 import org.testng.annotations.Test;
  30 
  31 import jdk.test.lib.dcmd.CommandExecutor;
  32 import jdk.test.lib.dcmd.JMXExecutor;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 
  35 /*
  36  * @test
  37  * @summary Test that various diagnostic commands which can show core reflection
  38  *          invocation targets do so correctly (See: JDK-8203343).
  39  * @library /test/lib
  40  * @run testng ShowReflectionTargetTest
  41  * @author stuefe
  42  */
  43 
  44 public class ShowReflectionTargetTest {
  45 
  46     @SuppressWarnings("unused")
  47     private static class Dummy {
  48         int _i;
  49         public Dummy(int i) { _i = i; }
  50         public int get_i() { return _i; }
  51     }
  52 
  53     public void run(CommandExecutor executor) throws Exception {
  54         // Do some reflection, enough times to hit the sun.reflect.inflationThreshold and force
  55         // generation of reflection accessor classes.
  56         Class<?> c = Class.forName("ShowReflectionTargetTest$Dummy");
  57         Constructor<?> ctor = c.getConstructor(int.class);
  58         Method m = c.getMethod("get_i");
  59         for (int i = 0; i < 100; i ++) {
  60             Object o = ctor.newInstance(i);
  61             int j = ((Integer)m.invoke(o)).intValue();
  62             Assert.assertEquals(j, i);
  63         }
  64 
  65         // Now invoke VM.class_hierarchy and check its output.
  66         // Should show reflection targets, e.g.:
  67         // ....
  68         //        |--jdk.internal.reflect.MagicAccessorImpl/null
  69         //        |  |--jdk.internal.reflect.FieldAccessorImpl/null
  70         //        |  |  |--jdk.internal.reflect.UnsafeFieldAccessorImpl/null
  71         //        |  |  |  |--jdk.internal.reflect.UnsafeStaticFieldAccessorImpl/null
  72         //        |  |  |  |  |--jdk.internal.reflect.UnsafeQualifiedStaticFieldAccessorImpl/null
  73         //        |  |  |  |  |  |--jdk.internal.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl/null
  74         //        |  |--jdk.internal.reflect.ConstructorAccessorImpl/null
  75         //        |  |  |--jdk.internal.reflect.DelegatingConstructorAccessorImpl/null
  76         //        |  |  |--jdk.internal.reflect.NativeConstructorAccessorImpl/null
  77         // >       |  |  |--jdk.internal.reflect.GeneratedConstructorAccessor1/0x00007f75f04889b0 (invokes: java/lang/management/ManagementPermission::<init> (Ljava/lang/String;)V)
  78         // >       |  |  |--jdk.internal.reflect.GeneratedConstructorAccessor2/0x00007f75f0494990 (invokes: ShowReflectionTargetTest$Dummy::<init> (I)V)
  79         //        |  |  |--jdk.internal.reflect.BootstrapConstructorAccessorImpl/null
  80         //        |  |--jdk.internal.reflect.MethodAccessorImpl/null
  81         // >       |  |  |--jdk.internal.reflect.GeneratedMethodAccessor1/0x00007f75f0494450 (invokes: ShowReflectionTargetTest$Dummy::get_i ()I)
  82         //        |  |  |--jdk.internal.reflect.DelegatingMethodAccessorImpl/null
  83         // ...


  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 import java.lang.reflect.Constructor;
  26 import java.lang.reflect.Method;
  27 
  28 import org.testng.Assert;
  29 import org.testng.annotations.Test;
  30 
  31 import jdk.test.lib.dcmd.CommandExecutor;
  32 import jdk.test.lib.dcmd.JMXExecutor;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 
  35 /*
  36  * @test
  37  * @summary Test that various diagnostic commands which can show core reflection
  38  *          invocation targets do so correctly (See: JDK-8203343).
  39  * @library /test/lib
  40  * @run testng/othervm -Dsun.reflect.noInflation=true ShowReflectionTargetTest
  41  * @author stuefe
  42  */
  43 
  44 public class ShowReflectionTargetTest {
  45 
  46     @SuppressWarnings("unused")
  47     private static class Dummy {
  48         int _i;
  49         public Dummy(int i) { _i = i; }
  50         public int get_i() { return _i; }
  51     }
  52 
  53     public void run(CommandExecutor executor) throws Exception {
  54         // Do some reflection; since we set -Dsun.reflect.noInflation=true, this should
  55         // immediately generate Generated{Method|Constructor}Accessor objects.
  56         Class<?> c = Class.forName("ShowReflectionTargetTest$Dummy");
  57         Constructor<?> ctor = c.getConstructor(int.class);
  58         Method m = c.getMethod("get_i");
  59 
  60         Object o = ctor.newInstance(17);
  61         int j = ((Integer)m.invoke(o)).intValue();
  62         Assert.assertEquals(j, 17);

  63 
  64         // Now invoke VM.class_hierarchy and check its output.
  65         // Should show reflection targets, e.g.:
  66         // ....
  67         //        |--jdk.internal.reflect.MagicAccessorImpl/null
  68         //        |  |--jdk.internal.reflect.FieldAccessorImpl/null
  69         //        |  |  |--jdk.internal.reflect.UnsafeFieldAccessorImpl/null
  70         //        |  |  |  |--jdk.internal.reflect.UnsafeStaticFieldAccessorImpl/null
  71         //        |  |  |  |  |--jdk.internal.reflect.UnsafeQualifiedStaticFieldAccessorImpl/null
  72         //        |  |  |  |  |  |--jdk.internal.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl/null
  73         //        |  |--jdk.internal.reflect.ConstructorAccessorImpl/null
  74         //        |  |  |--jdk.internal.reflect.DelegatingConstructorAccessorImpl/null
  75         //        |  |  |--jdk.internal.reflect.NativeConstructorAccessorImpl/null
  76         // >       |  |  |--jdk.internal.reflect.GeneratedConstructorAccessor1/0x00007f75f04889b0 (invokes: java/lang/management/ManagementPermission::<init> (Ljava/lang/String;)V)
  77         // >       |  |  |--jdk.internal.reflect.GeneratedConstructorAccessor2/0x00007f75f0494990 (invokes: ShowReflectionTargetTest$Dummy::<init> (I)V)
  78         //        |  |  |--jdk.internal.reflect.BootstrapConstructorAccessorImpl/null
  79         //        |  |--jdk.internal.reflect.MethodAccessorImpl/null
  80         // >       |  |  |--jdk.internal.reflect.GeneratedMethodAccessor1/0x00007f75f0494450 (invokes: ShowReflectionTargetTest$Dummy::get_i ()I)
  81         //        |  |  |--jdk.internal.reflect.DelegatingMethodAccessorImpl/null
  82         // ...
< prev index next >