Java Code Examples for jdk.test.lib.Utils#waitForCondition()

The following examples show how to use jdk.test.lib.Utils#waitForCondition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCompilerPhase.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();

    // Provoke compilation
    Method mtd = TestCompilerPhase.class.getDeclaredMethod(METHOD_NAME, new Class[0]);
    WhiteBox WB = WhiteBox.getWhiteBox();
    if (!WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_FULL_OPTIMIZATION)) {
        WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_SIMPLE);
    }
    Utils.waitForCondition(() -> WB.isMethodCompiled(mtd));
    dummyMethod();

    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        System.out.println("Event:" + event);
        Events.assertField(event, "phase").notEmpty();
        Events.assertField(event, "compileId").atLeast(0);
        Events.assertField(event, "phaseLevel").atLeast((short)0).atMost((short)4);
        Events.assertEventThread(event);
    }
}
 
Example 2
Source File: TestCompilerPhase.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();

    // Provoke compilation
    Method mtd = TestCompilerPhase.class.getDeclaredMethod(METHOD_NAME, new Class[0]);
    WhiteBox WB = WhiteBox.getWhiteBox();
    if (!WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_FULL_OPTIMIZATION)) {
        WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_SIMPLE);
    }
    Utils.waitForCondition(() -> WB.isMethodCompiled(mtd));
    dummyMethod();

    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        System.out.println("Event:" + event);
        Events.assertField(event, "phase").notEmpty();
        Events.assertField(event, "compileId").atLeast(0);
        Events.assertField(event, "phaseLevel").atLeast((short)0).atMost((short)4);
        Events.assertEventThread(event);
    }
}
 
Example 3
Source File: CompileCodeTestCase.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public NMethod compile(int level) {
    String directive = "[{ match: \"" + executable.getDeclaringClass().getName().replace('.', '/')
            + "." + (executable instanceof Constructor ? "<init>" : executable.getName())
            + "\", " + "BackgroundCompilation: false }]";
    if (WB.addCompilerDirective(directive) != 1) {
        throw new Error("Failed to add compiler directive: " + directive);
    }
    boolean enqueued = WB.enqueueMethodForCompilation(executable,
            level, bci);
    if (!enqueued) {
        throw new Error(String.format(
                "%s can't be enqueued for %scompilation on level %d",
                executable, bci >= 0 ? "osr-" : "", level));
    }
    Utils.waitForCondition(() -> WB.isMethodCompiled(executable, isOsr));
    return NMethod.get(executable, isOsr);
}
 
Example 4
Source File: CompileAction.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkCompilation(Executable executable,
                                     int level,
                                     boolean expectedCompiled) {
    execute(executable);
    WHITE_BOX.enqueueMethodForCompilation(executable, level);
    Utils.waitForCondition(
            () -> {
                execute(executable);
                return !WHITE_BOX.isMethodQueuedForCompilation(executable);
            }, 100L);
    execute(executable);
    boolean isCompilable = WHITE_BOX.isMethodCompilable(executable, level);
    Asserts.assertEQ(isCompilable, expectedCompiled,
            String.format("FAILED: method %s compilable: %b, but should: %b"
                    + " on required level: %d", executable, isCompilable,
                    expectedCompiled, level));
}
 
Example 5
Source File: CiReplayBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void remove(String item) {
    File toDelete = new File(item);
    toDelete.delete();
    if (Platform.isWindows()) {
        Utils.waitForCondition(() -> !toDelete.exists());
    }
}
 
Example 6
Source File: CodeCacheUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static final void hitUsageThreshold(MemoryPoolMXBean bean,
        BlobType btype) {
    long initialSize = bean.getUsage().getUsed();
    bean.setUsageThreshold(initialSize + 1);
    long usageThresholdCount = bean.getUsageThresholdCount();
    long addr = WB.allocateCodeBlob(1, btype.id);
    WB.fullGC();
    Utils.waitForCondition(()
            -> bean.getUsageThresholdCount() == usageThresholdCount + 1);
    WB.freeCodeBlob(addr);
}
 
Example 7
Source File: PoolsIndependenceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected void runTest() {
    MemoryPoolMXBean bean = btype.getMemoryPool();
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
            addNotificationListener(this, null, null);
    bean.setUsageThreshold(bean.getUsage().getUsed() + 1);
    long beginTimestamp = System.currentTimeMillis();
    CodeCacheUtils.WB.allocateCodeBlob(
            CodeCacheUtils.ALLOCATION_SIZE, btype.id);
    CodeCacheUtils.WB.fullGC();
    /* waiting for expected event to be received plus double the time took
     to receive expected event(for possible unexpected) and
     plus 1 second in case expected event received (almost)immediately */
    Utils.waitForCondition(() -> {
        long currentTimestamp = System.currentTimeMillis();
        int eventsCount
                = counters.get(btype.getMemoryPool().getName()).get();
        if (eventsCount > 0) {
            if (eventsCount > 1) {
                return true;
            }
            long timeLastEventTook
                    = beginTimestamp - lastEventTimestamp;
            long timeoutValue
                    = 1000L + beginTimestamp + 3L * timeLastEventTook;
            return currentTimestamp > timeoutValue;
        }
        return false;
    });
    for (BlobType bt : BlobType.getAvailable()) {
        int expectedNotificationsAmount = bt.equals(btype) ? 1 : 0;
        CodeCacheUtils.assertEQorGTE(btype, counters.get(bt.getMemoryPool().getName()).get(),
                expectedNotificationsAmount, String.format("Unexpected "
                        + "amount of notifications for pool: %s",
                        bt.getMemoryPool().getName()));
    }
    try {
        ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
                removeNotificationListener(this);
    } catch (ListenerNotFoundException ex) {
        throw new AssertionError("Can't remove notification listener", ex);
    }
    System.out.printf("INFO: Scenario with %s finished%n", bean.getName());
}
 
Example 8
Source File: SegmentedCodeCacheDtraceTestWorker.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void waitForCompilation(Executable executable, int compLevel) {
    if (compLevel > 0) {
        Utils.waitForCondition(() -> wb.isMethodCompiled(executable));
    }
}