当前位置: 首页>>代码示例>>Java>>正文


Java Reference.reachabilityFence方法代码示例

本文整理汇总了Java中java.lang.ref.Reference.reachabilityFence方法的典型用法代码示例。如果您正苦于以下问题:Java Reference.reachabilityFence方法的具体用法?Java Reference.reachabilityFence怎么用?Java Reference.reachabilityFence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.ref.Reference的用法示例。


在下文中一共展示了Reference.reachabilityFence方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fenced

import java.lang.ref.Reference; //导入方法依赖的package包/类
public static boolean fenced() {
    AtomicBoolean finalized = new AtomicBoolean();
    MyFinalizeable o = new MyFinalizeable(finalized);

    for (int i = 0; i < LOOP_ITERS; i++) {
        if (finalized.get()) break;
        if (i > WARMUP_LOOP_ITERS) {
            System.gc();
            System.runFinalization();
        }
    }

    Reference.reachabilityFence(o);

    return finalized.get();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ReachabilityFenceTest.java

示例2: testCleanupSecret

import java.lang.ref.Reference; //导入方法依赖的package包/类
static void testCleanupSecret(String algorithm) throws Exception {
    KeyGenerator desGen = KeyGenerator.getInstance(algorithm, SunJCEProvider);
    SecretKey key = desGen.generateKey();

    // Break into the implementation to observe the key byte array.
    Class<?> keyClass = key.getClass();
    Field keyField = keyClass.getDeclaredField("key");
    keyField.setAccessible(true);
    byte[] array = (byte[])keyField.get(key);

    byte[] zeros = new byte[array.length];
    do {
        // Wait for array to be cleared;  if not cleared test will timeout
        System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));
        key = null;
        System.gc();        // attempt to reclaim the key
    } while (Arrays.compare(zeros, array) != 0);
    System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));

    Reference.reachabilityFence(key); // Keep key alive
    Reference.reachabilityFence(array); // Keep array alive
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DESKeyCleanupTest.java

示例3: testCleanupSecret

import java.lang.ref.Reference; //导入方法依赖的package包/类
static void testCleanupSecret(String algorithm, SecretKey key) throws Exception {

        // Break into the implementation to observe the key byte array.
        Class<?> keyClass = key.getClass();
        Field keyField = keyClass.getDeclaredField("key");
        keyField.setAccessible(true);
        byte[] array = (byte[])keyField.get(key);

        byte[] zeros = new byte[array.length];
        do {
            // Wait for array to be cleared;  if not cleared test will timeout
            System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));
            key = null;
            System.gc();        // attempt to reclaim the key
        } while (Arrays.compare(zeros, array) != 0);
        System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));

        Reference.reachabilityFence(key); // Keep key alive
        Reference.reachabilityFence(array); // Keep array alive
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:PBEKeyCleanupTest.java

示例4: PhantomCleanable

import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
 * Constructs new {@code PhantomCleanable} with
 * {@code non-null referent} and {@code non-null cleaner}.
 * The {@code cleaner} is not retained; it is only used to
 * register the newly constructed {@link Cleaner.Cleanable Cleanable}.
 *
 * @param referent the referent to track
 * @param cleaner  the {@code Cleaner} to register with
 */
public PhantomCleanable(T referent, Cleaner cleaner) {
    super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue);
    this.list = CleanerImpl.getCleanerImpl(cleaner).phantomCleanableList;
    insert();

    // Ensure referent and cleaner remain accessible
    Reference.reachabilityFence(referent);
    Reference.reachabilityFence(cleaner);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PhantomCleanable.java

示例5: WeakCleanable

import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
 * Constructs new {@code WeakCleanableReference} with
 * {@code non-null referent} and {@code non-null cleaner}.
 * The {@code cleaner} is not retained by this reference; it is only used
 * to register the newly constructed {@link Cleaner.Cleanable Cleanable}.
 *
 * @param referent the referent to track
 * @param cleaner  the {@code Cleaner} to register new reference with
 */
public WeakCleanable(T referent, Cleaner cleaner) {
    super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue);
    list = CleanerImpl.getCleanerImpl(cleaner).weakCleanableList;
    insert();

    // Ensure referent and cleaner remain accessible
    Reference.reachabilityFence(referent);
    Reference.reachabilityFence(cleaner);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:WeakCleanable.java

示例6: SoftCleanable

import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
 * Constructs new {@code SoftCleanableReference} with
 * {@code non-null referent} and {@code non-null cleaner}.
 * The {@code cleaner} is not retained by this reference; it is only used
 * to register the newly constructed {@link Cleaner.Cleanable Cleanable}.
 *
 * @param referent the referent to track
 * @param cleaner  the {@code Cleaner} to register with
 */
public SoftCleanable(T referent, Cleaner cleaner) {
    super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue);
    list = CleanerImpl.getCleanerImpl(cleaner).softCleanableList;
    insert();

    // Ensure referent and cleaner remain accessible
    Reference.reachabilityFence(referent);
    Reference.reachabilityFence(cleaner);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:SoftCleanable.java

示例7: checkShouldNotClear

import java.lang.ref.Reference; //导入方法依赖的package包/类
private void checkShouldNotClear() throws Exception {
    System.out.println("running checkShouldNotClear");
    try {
        int value = 20;
        try {
            remember(value);
            checkValue(value);
            gcUntilOld(testObject);
            // Block concurrent cycle until we're ready.
            WB.requestConcurrentGCPhase("IDLE");
            checkValue(value);
            testObject = null; // Discard strong ref
            // Run through mark_from_roots.
            WB.requestConcurrentGCPhase("BEFORE_REMARK");
            // Fetch weak ref'ed object.  Should be kept alive now.
            Object recovered = getObject();
            if (recovered == null) {
                throw new RuntimeException("unexpected clear during mark");
            }
            // Finish collection, including reference processing.
            // Block any further cycles while we finish check.
            WB.requestConcurrentGCPhase("IDLE");
            // Fetch weak ref'ed object.  Referent is manifestly
            // live in recovered; the earlier fetch should have
            // kept it alive through collection, so weak ref
            // should not have been cleared.
            if (getObject() == null) {
                // 8166188 problem results in not doing the
                // keep-alive of earlier getObject result, so
                // recovered is now reachable but not marked.
                // We may eventually crash.
                throw new RuntimeException("cleared jweak for live object");
            }
            Reference.reachabilityFence(recovered);
        } finally {
            forget();
        }
    } finally {
        // Remove request.
        WB.requestConcurrentGCPhase("ANY");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:TestJNIWeakG1.java

示例8: doClientSide

import java.lang.ref.Reference; //导入方法依赖的package包/类
SBListener doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLSocketFactory sslsf =
            (SSLSocketFactory) SSLSocketFactory.getDefault();

        try {
                SSLSocket sslSocket = (SSLSocket)
                    sslsf.createSocket("localhost", serverPort);
                InputStream sslIS = sslSocket.getInputStream();
                OutputStream sslOS = sslSocket.getOutputStream();

            sslOS.write(280);
            sslOS.flush();
            sslIS.read();

            sslOS.close();
            sslIS.close();

            SSLSession sslSession = sslSocket.getSession();
            System.out.printf(" sslSession: %s %n   %s%n", sslSession, sslSession.getClass());
            SBListener sbListener = new SBListener(sslSession);

            sslSession.putValue("x", sbListener);

            sslSession.invalidate();

            sslSocket.close();

            sslOS = null;
            sslIS = null;
            sslSession = null;
            sslSocket = null;
            Reference.reachabilityFence(sslOS);
            Reference.reachabilityFence(sslIS);
            Reference.reachabilityFence(sslSession);
            Reference.reachabilityFence(sslSocket);

            return sbListener;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:51,代码来源:SSLSessionFinalizeTest.java

示例9: computeIfAbsent

import java.lang.ref.Reference; //导入方法依赖的package包/类
/**
 * If the specified key pair is not already associated with a value,
 * attempts to compute its value using the given mapping function
 * and enters it into this WeakPairMap unless {@code null}. The entire
 * method invocation is performed atomically, so the function is
 * applied at most once per key pair. Some attempted update operations
 * on this WeakPairMap by other threads may be blocked while computation
 * is in progress, so the computation should be short and simple,
 * and must not attempt to update any other mappings of this WeakPairMap.
 *
 * @param k1              the 1st of the pair of keys with which the
 *                        computed value is to be associated
 * @param k2              the 2nd of the pair of keys with which the
 *                        computed value is to be associated
 * @param mappingFunction the function to compute a value
 * @return the current (existing or computed) value associated with
 * the specified key pair, or null if the computed value is null
 * @throws NullPointerException  if any of the specified keys or
 *                               mappingFunction is null
 * @throws IllegalStateException if the computation detectably
 *                               attempts a recursive update to this map
 *                               that would otherwise never complete
 * @throws RuntimeException      or Error if the mappingFunction does so, in
 *                               which case the mapping is left unestablished
 */
public V computeIfAbsent(K1 k1, K2 k2,
                         BiFunction<? super K1, ? super K2, ? extends V>
                             mappingFunction) {
    expungeStaleAssociations();
    try {
        return map.computeIfAbsent(
            Pair.weak(k1, k2, queue),
            pair -> mappingFunction.apply(pair.first(), pair.second()));
    } finally {
        Reference.reachabilityFence(k1);
        Reference.reachabilityFence(k2);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:WeakPairMap.java


注:本文中的java.lang.ref.Reference.reachabilityFence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。