Java Code Examples for sun.misc.VM#isBooted()

The following examples show how to use sun.misc.VM#isBooted() . 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: Finalizer.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
static void runAllFinalizers() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f;
                synchronized (lock) {
                    f = unfinalized;
                    if (f == null) break;
                    unfinalized = f.next;
                }
                f.runFinalizer(jla);
            }}});
}
 
Example 2
Source File: Finalizer.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
static void runAllFinalizers() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            // in case of recursive call to run()
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f;
                synchronized (lock) {
                    f = unfinalized;
                    if (f == null) break;
                    unfinalized = f.next;
                }
                f.runFinalizer(jla);
            }}});
}
 
Example 3
Source File: Finalizer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void runFinalization() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            // in case of recursive call to run()
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f = (Finalizer)queue.poll();
                if (f == null) break;
                f.runFinalizer(jla);
            }
        }
    });
}
 
Example 4
Source File: Finalizer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void runFinalization() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f = (Finalizer)queue.poll();
                if (f == null) break;
                f.runFinalizer(jla);
            }
        }
    });
}
 
Example 5
Source File: Finalizer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void runFinalization() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f = (Finalizer)queue.poll();
                if (f == null) break;
                f.runFinalizer(jla);
            }
        }
    });
}
 
Example 6
Source File: Finalizer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void runAllFinalizers() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            // in case of recursive call to run()
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f;
                synchronized (lock) {
                    f = unfinalized;
                    if (f == null) break;
                    unfinalized = f.next;
                }
                f.runFinalizer(jla);
            }}});
}
 
Example 7
Source File: Finalizer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void runFinalization() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f = (Finalizer)queue.poll();
                if (f == null) break;
                f.runFinalizer(jla);
            }
        }
    });
}
 
Example 8
Source File: Finalizer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void runAllFinalizers() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f;
                synchronized (lock) {
                    f = unfinalized;
                    if (f == null) break;
                    unfinalized = f.next;
                }
                f.runFinalizer(jla);
            }}});
}
 
Example 9
Source File: Finalizer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void add() {
    synchronized (lock) {
        if (VM.isBooted() && TenantGlobals.isDataIsolationEnabled() && TenantContainer.current() != null) {
            TenantData td = TenantContainer.current().getTenantData();
            Finalizer tenantUnfinalized = td.getFieldValue(Finalizer.class, ID_UNFINALIZED);
            if (tenantUnfinalized != null) {
                this.next = tenantUnfinalized;
                tenantUnfinalized.prev = this;
            }
            td.setFieldValue(Finalizer.class, ID_UNFINALIZED, this);
        } else {
            if (unfinalized != null) {
                this.next = unfinalized;
                unfinalized.prev = this;
            }
            unfinalized = this;
        }
    }
}
 
Example 10
Source File: Finalizer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void runFinalization() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f = (Finalizer)queue.poll();
                if (f == null) break;
                f.runFinalizer(jla);
            }
        }
    });
}
 
Example 11
Source File: Finalizer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void runAllFinalizers() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f;
                synchronized (lock) {
                    f = unfinalized;
                    if (f == null) break;
                    unfinalized = f.next;
                }
                f.runFinalizer(jla);
            }}});
}
 
Example 12
Source File: Finalizer.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
static void runFinalization() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f = (Finalizer)queue.poll();
                if (f == null) break;
                f.runFinalizer(jla);
            }
        }
    });
}
 
Example 13
Source File: Finalizer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void runAllFinalizers() {
    if (!VM.isBooted()) {
        return;
    }

    forkSecondaryFinalizer(new Runnable() {
        private volatile boolean running;
        public void run() {
            // in case of recursive call to run()
            if (running)
                return;
            final JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
            running = true;
            for (;;) {
                Finalizer f;
                if (TenantGlobals.isDataIsolationEnabled() && TenantContainer.current() != null) {
                    TenantData td = TenantContainer.current().getTenantData();
                    synchronized (lock) {
                        f = td.getFieldValue(Finalizer.class, ID_UNFINALIZED);
                        if (f == null) break;
                        td.setFieldValue(Finalizer.class, ID_UNFINALIZED, f.next);
                    }
                } else {
                    synchronized (lock) {
                        f = unfinalized;
                        if (f == null) break;
                        unfinalized = f.next;
                    }
                }
                f.runFinalizer(jla);
            }}});
}
 
Example 14
Source File: Bits.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
static void reserveMemory(long size, int cap) {
    synchronized (Bits.class) {
        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }
        // -XX:MaxDirectMemorySize limits the total capacity rather than the
        // actual memory usage, which will differ when buffers are page
        // aligned.
        if (cap <= maxMemory - totalCapacity) {
            reservedMemory += size;
            totalCapacity += cap;
            count++;
            return;
        }
    }

    System.gc();
    try {
        Thread.sleep(100);
    } catch (InterruptedException x) {
        // Restore interrupt status
        Thread.currentThread().interrupt();
    }
    synchronized (Bits.class) {
        if (totalCapacity + cap > maxMemory)
            throw new OutOfMemoryError("Direct buffer memory");
        reservedMemory += size;
        totalCapacity += cap;
        count++;
    }

}
 
Example 15
Source File: Finalizer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static ReferenceQueue<Object> getQueue() {
    if (VM.isBooted() && TenantGlobals.isDataIsolationEnabled() && TenantContainer.current() != null) {
        return TenantContainer.current().getFieldValue(Finalizer.class, "queue",
                Finalizer::initTenantReferenceQueue);
    } else {
        return queue;
    }
}
 
Example 16
Source File: Bits.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void reserveMemory(long size, int cap) {
    synchronized (Bits.class) {
        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }
        // -XX:MaxDirectMemorySize limits the total capacity rather than the
        // actual memory usage, which will differ when buffers are page
        // aligned.
        if (cap <= maxMemory - totalCapacity) {
            reservedMemory += size;
            totalCapacity += cap;
            count++;
            return;
        }
    }

    System.gc();
    try {
        Thread.sleep(100);
    } catch (InterruptedException x) {
        // Restore interrupt status
        Thread.currentThread().interrupt();
    }
    synchronized (Bits.class) {
        if (totalCapacity + cap > maxMemory)
            throw new OutOfMemoryError("Direct buffer memory");
        reservedMemory += size;
        totalCapacity += cap;
        count++;
    }

}
 
Example 17
Source File: Bits.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void reserveMemory(long size, int cap) {

        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }

        // optimist!
        if (tryReserveMemory(size, cap)) {
            return;
        }

        final JavaLangRefAccess jlra = SharedSecrets.getJavaLangRefAccess();

        // retry while helping enqueue pending Reference objects
        // which includes executing pending Cleaner(s) which includes
        // Cleaner(s) that free direct buffer memory
        while (jlra.tryHandlePendingReference()) {
            if (tryReserveMemory(size, cap)) {
                return;
            }
        }

        // trigger VM's Reference processing
        System.gc();

        // a retry loop with exponential back-off delays
        // (this gives VM some time to do it's job)
        boolean interrupted = false;
        try {
            long sleepTime = 1;
            int sleeps = 0;
            while (true) {
                if (tryReserveMemory(size, cap)) {
                    return;
                }
                if (sleeps >= MAX_SLEEPS) {
                    break;
                }
                if (!jlra.tryHandlePendingReference()) {
                    try {
                        Thread.sleep(sleepTime);
                        sleepTime <<= 1;
                        sleeps++;
                    } catch (InterruptedException e) {
                        interrupted = true;
                    }
                }
            }

            // no luck
            throw new OutOfMemoryError("Direct buffer memory");

        } finally {
            if (interrupted) {
                // don't swallow interrupts
                Thread.currentThread().interrupt();
            }
        }
    }
 
Example 18
Source File: Bits.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void reserveMemory(long size, int cap) {

        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }

        // optimist!
        if (tryReserveMemory(size, cap)) {
            return;
        }

        final JavaLangRefAccess jlra = SharedSecrets.getJavaLangRefAccess();

        // retry while helping enqueue pending Reference objects
        // which includes executing pending Cleaner(s) which includes
        // Cleaner(s) that free direct buffer memory
        while (jlra.tryHandlePendingReference()) {
            if (tryReserveMemory(size, cap)) {
                return;
            }
        }

        // trigger VM's Reference processing
        System.gc();

        // a retry loop with exponential back-off delays
        // (this gives VM some time to do it's job)
        boolean interrupted = false;
        try {
            long sleepTime = 1;
            int sleeps = 0;
            while (true) {
                if (tryReserveMemory(size, cap)) {
                    return;
                }
                if (sleeps >= MAX_SLEEPS) {
                    break;
                }
                if (!jlra.tryHandlePendingReference()) {
                    try {
                        Thread.sleep(sleepTime);
                        sleepTime <<= 1;
                        sleeps++;
                    } catch (InterruptedException e) {
                        interrupted = true;
                    }
                }
            }

            // no luck
            throw new OutOfMemoryError("Direct buffer memory");

        } finally {
            if (interrupted) {
                // don't swallow interrupts
                Thread.currentThread().interrupt();
            }
        }
    }
 
Example 19
Source File: Bits.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void reserveMemory(long size, int cap) {

        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }

        // optimist!
        if (tryReserveMemory(size, cap)) {
            return;
        }

        final JavaLangRefAccess jlra = SharedSecrets.getJavaLangRefAccess();

        // retry while helping enqueue pending Reference objects
        // which includes executing pending Cleaner(s) which includes
        // Cleaner(s) that free direct buffer memory
        while (jlra.tryHandlePendingReference()) {
            if (tryReserveMemory(size, cap)) {
                return;
            }
        }

        // trigger VM's Reference processing
        System.gc();

        // a retry loop with exponential back-off delays
        // (this gives VM some time to do it's job)
        boolean interrupted = false;
        try {
            long sleepTime = 1;
            int sleeps = 0;
            while (true) {
                if (tryReserveMemory(size, cap)) {
                    return;
                }
                if (sleeps >= MAX_SLEEPS) {
                    break;
                }
                if (!jlra.tryHandlePendingReference()) {
                    try {
                        Thread.sleep(sleepTime);
                        sleepTime <<= 1;
                        sleeps++;
                    } catch (InterruptedException e) {
                        interrupted = true;
                    }
                }
            }

            // no luck
            throw new OutOfMemoryError("Direct buffer memory");

        } finally {
            if (interrupted) {
                // don't swallow interrupts
                Thread.currentThread().interrupt();
            }
        }
    }
 
Example 20
Source File: System.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the system property indicated by the specified key.
 * <p>
 * First, if there is a security manager, its
 * <code>checkPropertyAccess</code> method is called with the key as
 * its argument. This may result in a SecurityException.
 * <p>
 * If there is no current set of system properties, a set of system
 * properties is first created and initialized in the same manner as
 * for the <code>getProperties</code> method.
 *
 * @param      key   the name of the system property.
 * @return     the string value of the system property,
 *             or <code>null</code> if there is no property with that key.
 *
 * @exception  SecurityException  if a security manager exists and its
 *             <code>checkPropertyAccess</code> method doesn't allow
 *              access to the specified system property.
 * @exception  NullPointerException if <code>key</code> is
 *             <code>null</code>.
 * @exception  IllegalArgumentException if <code>key</code> is empty.
 * @see        #setProperty
 * @see        java.lang.SecurityException
 * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
 * @see        java.lang.System#getProperties()
 */
public static String getProperty(String key) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
        sm.checkPropertyAccess(key);
    }

    if(VM.isBooted() && TenantGlobals.isDataIsolationEnabled()
       && null != TenantContainer.current()) {
        return TenantContainer.current().getProperty(key);
    } else {
        return props.getProperty(key);
    }
}