< prev index next >

test/jdk/jfr/event/compiler/TestCodeCacheFull.java

Print this page
rev 13431 : Fix JFR code cache test failures


  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.jfr.event.compiler;
  27 
  28 import java.util.List;
  29 
  30 import jdk.jfr.Recording;
  31 import jdk.jfr.consumer.RecordedEvent;
  32 import jdk.test.lib.Asserts;
  33 import jdk.test.lib.jfr.EventNames;
  34 import jdk.test.lib.jfr.Events;
  35 import sun.hotspot.WhiteBox;
  36 import sun.hotspot.code.BlobType;
  37 
  38 /**
  39  * @test TestCodeCacheFull
  40  * 
  41  *
  42  * @library /lib /

  43  * 
  44  *          jdk.management.jfr
  45  * @build sun.hotspot.WhiteBox
  46  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  47  *
  48  * @run main/othervm -Xbootclasspath/a:.
  49  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  50  *     -XX:+SegmentedCodeCache -XX:-UseLargePages jdk.jfr.event.compiler.TestCodeCacheFull
  51  * @run main/othervm -Xbootclasspath/a:.
  52  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  53  *     -XX:-SegmentedCodeCache jdk.jfr.event.compiler.TestCodeCacheFull
  54  */
  55 public class TestCodeCacheFull {
  56 
  57     public static void main(String[] args) throws Exception {
  58         for (BlobType btype : BlobType.getAvailable()) {
  59             testWithBlobType(btype, calculateAvailableSize(btype));
  60         }
  61     }
  62 
  63     private static void testWithBlobType(BlobType btype, long availableSize) throws Exception {
  64         Recording r = new Recording();
  65         r.enable(EventNames.CodeCacheFull);
  66         r.start();
  67         WhiteBox.getWhiteBox().allocateCodeBlob(availableSize, btype.id);
  68         r.stop();
  69 
  70         List<RecordedEvent> events = Events.fromRecording(r);
  71         Events.hasEvents(events);
  72         RecordedEvent event = events.get(0);
  73 
  74         String codeBlobType = Events.assertField(event, "codeBlobType").notNull().getValue();
  75         BlobType blobType = blobTypeFromName(codeBlobType);
  76         Asserts.assertTrue(blobType.allowTypeWhenOverflow(blobType), "Unexpected overflow BlobType " + blobType.id);
  77         Events.assertField(event, "entryCount").atLeast(0);
  78         Events.assertField(event, "methodCount").atLeast(0);
  79         Events.assertEventThread(event);
  80         Events.assertField(event, "fullCount").atLeast(0);
  81         Events.assertField(event, "startAddress").notEqual(0L);
  82         Events.assertField(event, "commitedTopAddress").notEqual(0L);
  83         Events.assertField(event, "reservedTopAddress").notEqual(0L);
  84     }
  85 
  86     private static BlobType blobTypeFromName(String codeBlobTypeName) throws Exception {
  87         for (BlobType t : BlobType.getAvailable()) {
  88             if (t.beanName.equals(codeBlobTypeName)) {
  89                 return t;
  90             }
  91         }
  92         throw new Exception("Unexpected event " + codeBlobTypeName);
  93     }
  94 
  95     // Compute the available size for this BlobType by taking into account
  96     // that it may be stored in a different code heap in case it does not fit
  97     // into the current one.
  98     private static long calculateAvailableSize(BlobType btype) {
  99         long availableSize = btype.getSize();
 100         for (BlobType alternative : BlobType.getAvailable()) {
 101             if (btype.allowTypeWhenOverflow(alternative)) {
 102                 availableSize = Math.max(availableSize, alternative.getSize());
 103             }
 104         }
 105         return availableSize;
 106     }
 107 }


  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.jfr.event.compiler;
  27 
  28 import java.util.List;
  29 
  30 import jdk.jfr.Recording;
  31 import jdk.jfr.consumer.RecordedEvent;
  32 import jdk.test.lib.Asserts;
  33 import jdk.test.lib.jfr.EventNames;
  34 import jdk.test.lib.jfr.Events;
  35 import sun.hotspot.WhiteBox;
  36 import sun.hotspot.code.BlobType;
  37 
  38 /**
  39  * @test TestCodeCacheFull
  40  * 
  41  *
  42  * @library /lib
  43  * 
  44  *

  45  * @build sun.hotspot.WhiteBox
  46  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  47  *
  48  * @run main/othervm -Xbootclasspath/a:.
  49  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  50  *     -XX:-UseLargePages jdk.jfr.event.compiler.TestCodeCacheFull
  51  * @run main/othervm -Xbootclasspath/a:.
  52  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  53  *     jdk.jfr.event.compiler.TestCodeCacheFull
  54  */
  55 public class TestCodeCacheFull {
  56 
  57     public static void main(String[] args) throws Exception {
  58         for (BlobType btype : BlobType.getAvailable()) {
  59             testWithBlobType(btype, calculateAvailableSize(btype));
  60         }
  61     }
  62 
  63     private static void testWithBlobType(BlobType btype, long availableSize) throws Exception {
  64         Recording r = new Recording();
  65         r.enable(EventNames.CodeCacheFull);
  66         r.start();
  67         WhiteBox.getWhiteBox().allocateCodeBlob(availableSize, btype.id);
  68         r.stop();
  69 
  70         List<RecordedEvent> events = Events.fromRecording(r);
  71         Events.hasEvents(events);
  72         RecordedEvent event = events.get(0);
  73 
  74         String codeBlobType = Events.assertField(event, "codeBlobType").notNull().getValue();
  75         BlobType blobType = blobTypeFromName(codeBlobType);
  76         Asserts.assertTrue(blobType.allowTypeWhenOverflow(blobType), "Unexpected overflow BlobType " + blobType.id);
  77         Events.assertField(event, "entryCount").atLeast(0);
  78         Events.assertField(event, "methodCount").atLeast(0);
  79         Events.assertEventThread(event);
  80         Events.assertField(event, "fullCount").atLeast(0);
  81         Events.assertField(event, "startAddress").notEqual(0L);
  82         Events.assertField(event, "commitedTopAddress").notEqual(0L);
  83         Events.assertField(event, "reservedTopAddress").notEqual(0L);
  84     }
  85 
  86     private static BlobType blobTypeFromName(String codeBlobTypeName) throws Exception {
  87         for (BlobType t : BlobType.getAvailable()) {
  88             if (t.name.equals(codeBlobTypeName)) {
  89                 return t;
  90             }
  91         }
  92         throw new Exception("Unexpected event " + codeBlobTypeName);
  93     }
  94 
  95     // Compute the available size for this BlobType by taking into account
  96     // that it may be stored in a different code heap in case it does not fit
  97     // into the current one.
  98     private static long calculateAvailableSize(BlobType btype) {
  99         long availableSize = btype.getSize();
 100         for (BlobType alternative : BlobType.getAvailable()) {
 101             if (btype.allowTypeWhenOverflow(alternative)) {
 102                 availableSize = Math.max(availableSize, alternative.getSize());
 103             }
 104         }
 105         return availableSize;
 106     }
 107 }
< prev index next >