< prev index next >

test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineLeak.java

Print this page

 46 import jdk.test.lib.helpers.ClassFileInstaller;
 47 
 48 public class RedefineLeak {
 49     static class Tester {}
 50 
 51     static class LoggingTransformer implements ClassFileTransformer {
 52         static int transformCount = 0;
 53 
 54         public LoggingTransformer() {}
 55 
 56         public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined,
 57             ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
 58 
 59             transformCount++;
 60             if (transformCount % 1000 == 0) System.out.println("transformCount:" + transformCount);
 61             return null;
 62         }
 63     }
 64 
 65     public static void premain(String agentArgs, Instrumentation inst) throws Exception {

 66         LoggingTransformer t = new LoggingTransformer();
 67         inst.addTransformer(t, true);
 68         {
 69             Class demoClass = Class.forName("RedefineLeak$Tester");
 70 
 71             for (int i = 0; i < 10000; i++) {
 72                inst.retransformClasses(demoClass);
 73             }
 74         }
 75         System.gc();
 76     }
 77     private static void buildAgent() {
 78         try {
 79             ClassFileInstaller.main("RedefineLeak");
 80         } catch (Exception e) {
 81             throw new RuntimeException("Could not write agent classfile", e);
 82         }
 83 
 84         try {
 85             PrintWriter pw = new PrintWriter("MANIFEST.MF");

 46 import jdk.test.lib.helpers.ClassFileInstaller;
 47 
 48 public class RedefineLeak {
 49     static class Tester {}
 50 
 51     static class LoggingTransformer implements ClassFileTransformer {
 52         static int transformCount = 0;
 53 
 54         public LoggingTransformer() {}
 55 
 56         public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined,
 57             ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
 58 
 59             transformCount++;
 60             if (transformCount % 1000 == 0) System.out.println("transformCount:" + transformCount);
 61             return null;
 62         }
 63     }
 64 
 65     public static void premain(String agentArgs, Instrumentation inst) throws Exception {
 66         System.gc();
 67         LoggingTransformer t = new LoggingTransformer();
 68         inst.addTransformer(t, true);
 69         {
 70             Class demoClass = Class.forName("RedefineLeak$Tester");
 71 
 72             for (int i = 0; i < 10000; i++) {
 73                inst.retransformClasses(demoClass);
 74             }
 75         }
 76         System.gc();
 77     }
 78     private static void buildAgent() {
 79         try {
 80             ClassFileInstaller.main("RedefineLeak");
 81         } catch (Exception e) {
 82             throw new RuntimeException("Could not write agent classfile", e);
 83         }
 84 
 85         try {
 86             PrintWriter pw = new PrintWriter("MANIFEST.MF");
< prev index next >