Search in sources :

Example 26 with IntSupplier

use of java.util.function.IntSupplier in project graal by oracle.

the class CompilationFinalWeakReferencePartialEvaluationTest method compilationFinalWeakReferenceTest.

/**
 * {@link WeakReference} constant-folded but not embedded in compiled code.
 */
@Test
public void compilationFinalWeakReferenceTest() {
    String name = "compilationFinalWeakReferenceTest";
    FrameDescriptor fd = new FrameDescriptor();
    IntSupplier data = generateTestData();
    AbstractTestNode result = new CompilationFinalWeakReferenceTestNode(data);
    RootTestNode rootNode = new RootTestNode(fd, name, result);
    assertPartialEvalEquals("constant42", rootNode);
    OptimizedCallTarget callTarget = compileHelper(name, rootNode, new Object[0]);
    Assert.assertEquals(42, (int) callTarget.call(new Object[0]));
    assert data != null;
    WeakReference<IntSupplier> witness = new WeakReference<>(data);
    data = null;
    boolean cleared = false;
    for (int i = 1; i <= 5 && !cleared; i++) {
        System.gc();
        cleared = witness.get() == null;
    }
    // Reference not embedded in compiled code
    Assert.assertEquals(42, (int) callTarget.call(new Object[0]));
    assertTrue(callTarget.isValid());
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) IntSupplier(java.util.function.IntSupplier) WeakReference(java.lang.ref.WeakReference) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 27 with IntSupplier

use of java.util.function.IntSupplier in project graal by oracle.

the class CompilationFinalWeakReferencePartialEvaluationTest method compilationFinalWeakReferenceTestGC.

/**
 * {@link WeakReference} constant-folded and embedded in compiled code.
 */
@Test
public void compilationFinalWeakReferenceTestGC() {
    String name = "compilationFinalWeakReferenceTestGC";
    FrameDescriptor fd = new FrameDescriptor();
    IntSupplier data = generateTestData();
    AbstractTestNode result = new CompilationFinalWeakReferenceTestGCNode(data);
    RootTestNode rootNode = new RootTestNode(fd, name, result);
    OptimizedCallTarget callTarget = compileHelper(name, rootNode, new Object[] { data });
    Assert.assertEquals(42, (int) callTarget.call(new Object[] { data }));
    Assert.assertEquals(-1, (int) callTarget.call(new Object[] { null }));
    callTarget = compileHelper(name, rootNode, new Object[] { data });
    assertTrue(callTarget.isValid());
    assert data != null;
    clearDebugScopeTL();
    WeakReference<IntSupplier> witness = new WeakReference<>(data);
    data = null;
    boolean cleared = false;
    for (int i = 1; i <= 5 && !cleared; i++) {
        System.gc();
        cleared = witness.get() == null;
    }
    assertTrue("Test data should have been garbage collected at this point", cleared);
    // Compiled code had the collected reference embedded so it had to be invalidated
    assertFalse(callTarget.isValid());
    Assert.assertEquals(0xdead, (int) callTarget.call(new Object[] { null }));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) IntSupplier(java.util.function.IntSupplier) WeakReference(java.lang.ref.WeakReference) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 28 with IntSupplier

use of java.util.function.IntSupplier in project KursJava by SamouczekProgramisty.

the class ArticleExamples method instanceMethodReference.

private static void instanceMethodReference() {
    Object objectInstance = new Object();
    IntSupplier equalsMethodOnObject = objectInstance::hashCode;
    System.out.println(equalsMethodOnObject.getAsInt());
    // exactly the same as above, without method reference expression
    System.out.println(objectInstance.hashCode());
}
Also used : IntSupplier(java.util.function.IntSupplier)

Example 29 with IntSupplier

use of java.util.function.IntSupplier in project j2objc by google.

the class OptionalIntTest method testOrElseGet.

public void testOrElseGet() {
    IntSupplier alwaysFails = () -> {
        fail();
        return 57;
    };
    assertEquals(56, OptionalInt.of(56).orElseGet(alwaysFails));
    IntSupplier supplies57 = () -> 57;
    assertEquals(57, OptionalInt.empty().orElseGet(supplies57));
}
Also used : IntSupplier(java.util.function.IntSupplier)

Example 30 with IntSupplier

use of java.util.function.IntSupplier in project fmv by f-agu.

the class TextProgressBar method schedule.

// **********************************************
/**
 * @param progressInPercent
 * @param refreshPeriodMilliseconds
 */
private void schedule(IntSupplier progressInPercent, long refreshPeriodMilliseconds) {
    IntSupplier supplier = progressInPercent != null ? progressInPercent : () -> 0;
    timerTask = new TimerTask() {

        /**
         * @see java.util.TimerTask#run()
         */
        @Override
        public void run() {
            print(supplier.getAsInt());
        }
    };
    timer = new Timer();
    timer.scheduleAtFixedRate(timerTask, 0, refreshPeriodMilliseconds);
}
Also used : TimerTask(java.util.TimerTask) Timer(java.util.Timer) IntSupplier(java.util.function.IntSupplier)

Aggregations

IntSupplier (java.util.function.IntSupplier)39 Test (org.junit.Test)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 InetSocketAddress (java.net.InetSocketAddress)4 DatagramChannel (java.nio.channels.DatagramChannel)4 Selector (java.nio.channels.Selector)4 IHwButton (de.mossgrabers.framework.controller.hardware.IHwButton)3 SelectionKey (java.nio.channels.SelectionKey)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Supplier (java.util.function.Supplier)3 Collectors (java.util.stream.Collectors)3 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)2 ButtonID (de.mossgrabers.framework.controller.ButtonID)2 IHwLight (de.mossgrabers.framework.controller.hardware.IHwLight)2 WeakReference (java.lang.ref.WeakReference)2