java.util.logging.LoggingPermission#sun.misc.SharedSecrets源码实例Demo

下面列出了java.util.logging.LoggingPermission#sun.misc.SharedSecrets 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u60   文件: Finalizer.java
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);
            }}});
}
 
源代码2 项目: jdk8u-dev-jdk   文件: Finalizer.java
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);
            }
        }
    });
}
 
源代码3 项目: jdk8u_jdk   文件: Finalizer.java
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);
            }
        }
    });
}
 
源代码4 项目: openjdk-jdk8u   文件: PriorityQueue.java
/**
 * Reconstitutes the {@code PriorityQueue} instance from a stream
 * (that is, deserializes it).
 *
 * @param s the stream
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {
    // Read in size, and any hidden stuff
    s.defaultReadObject();

    // Read in (and discard) array length
    s.readInt();

    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, size);
    queue = new Object[size];

    // Read in all elements.
    for (int i = 0; i < size; i++)
        queue[i] = s.readObject();

    // Elements are guaranteed to be in "proper order", but the
    // spec has never explained what that might be.
    heapify();
}
 
源代码5 项目: jdk-1.7-annotated   文件: Finalizer.java
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);
            }
        }
    });
}
 
源代码6 项目: openjdk-jdk8u   文件: PreserveCombinerTest.java
public static void main(String[]args) throws Exception {
    final DomainCombiner dc = new DomainCombiner() {
        @Override
        public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
            return currentDomains; // basically a no-op
        }
    };

    // Get an instance of the saved ACC
    AccessControlContext saved = AccessController.getContext();
    // Simulate the stack ACC with a DomainCombiner attached
    AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc);

    // Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert
    // whether the DomainCombiner from the stack ACC is preserved
    boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() {
        @Override
        public Boolean run() {
            return dc == AccessController.getContext().getDomainCombiner();
        }
    }, stack, saved);

    if (!ret) {
        System.exit(1);
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: Finalizer.java
private static void forkSecondaryFinalizer(final Runnable proc) {
    AccessController.doPrivileged(
        new PrivilegedAction<Void>() {
            public Void run() {
                ThreadGroup tg = Thread.currentThread().getThreadGroup();
                for (ThreadGroup tgn = tg;
                     tgn != null;
                     tg = tgn, tgn = tg.getParent());
                Thread sft = new Thread(tg, proc, "Secondary finalizer");

                if (TenantGlobals.isDataIsolationEnabled() && TenantContainer.current() != null) {
                    SharedSecrets.getTenantAccess()
                            .registerServiceThread(TenantContainer.current(), sft);
                }

                sft.start();
                try {
                    sft.join();
                } catch (InterruptedException x) {
                    Thread.currentThread().interrupt();
                }
                return null;
            }});
}
 
源代码8 项目: jdk8u-jdk   文件: Finalizer.java
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);
            }}});
}
 
源代码9 项目: dragonwell8_jdk   文件: PriorityQueue.java
/**
 * Reconstitutes the {@code PriorityQueue} instance from a stream
 * (that is, deserializes it).
 *
 * @param s the stream
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {
    // Read in size, and any hidden stuff
    s.defaultReadObject();

    // Read in (and discard) array length
    s.readInt();

    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, size);
    queue = new Object[size];

    // Read in all elements.
    for (int i = 0; i < size; i++)
        queue[i] = s.readObject();

    // Elements are guaranteed to be in "proper order", but the
    // spec has never explained what that might be.
    heapify();
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: Finalizer.java
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);
            }
        }
    });
}
 
源代码11 项目: TencentKona-8   文件: PreserveCombinerTest.java
public static void main(String[]args) throws Exception {
    final DomainCombiner dc = new DomainCombiner() {
        @Override
        public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
            return currentDomains; // basically a no-op
        }
    };

    // Get an instance of the saved ACC
    AccessControlContext saved = AccessController.getContext();
    // Simulate the stack ACC with a DomainCombiner attached
    AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc);

    // Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert
    // whether the DomainCombiner from the stack ACC is preserved
    boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() {
        @Override
        public Boolean run() {
            return dc == AccessController.getContext().getDomainCombiner();
        }
    }, stack, saved);

    if (!ret) {
        System.exit(1);
    }
}
 
源代码12 项目: dragonwell8_jdk   文件: IdentityHashMap.java
/**
 * Reconstitutes the <tt>IdentityHashMap</tt> instance from a stream (i.e.,
 * deserializes it).
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException  {
    // Read in any hidden stuff
    s.defaultReadObject();

    // Read in size (number of Mappings)
    int size = s.readInt();
    if (size < 0)
        throw new java.io.StreamCorruptedException
            ("Illegal mappings count: " + size);
    int cap = capacity(size);
    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, cap);
    init(cap);

    // Read the keys and values, and put the mappings in the table
    for (int i=0; i<size; i++) {
        @SuppressWarnings("unchecked")
            K key = (K) s.readObject();
        @SuppressWarnings("unchecked")
            V value = (V) s.readObject();
        putForCreate(key, value);
    }
}
 
源代码13 项目: openjdk-jdk8u   文件: PolicyFile.java
PolicyInfo(int numCaches) {
    policyEntries = new ArrayList<>();
    identityPolicyEntries =
        Collections.synchronizedList(new ArrayList<PolicyEntry>(2));
    aliasMapping = Collections.synchronizedMap(new HashMap<>(11));

    pdMapping = new ProtectionDomainCache[numCaches];
    JavaSecurityProtectionDomainAccess jspda
        = SharedSecrets.getJavaSecurityProtectionDomainAccess();
    for (int i = 0; i < numCaches; i++) {
        pdMapping[i] = jspda.getProtectionDomainCache();
    }
    if (numCaches > 1) {
        random = new java.util.Random();
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: CopyOnWriteArrayList.java
/**
 * Reconstitutes this list from a stream (that is, deserializes it).
 * @param s the stream
 * @throws ClassNotFoundException if the class of a serialized object
 *         could not be found
 * @throws java.io.IOException if an I/O error occurs
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {

    s.defaultReadObject();

    // bind to new lock
    resetLock();

    // Read in array length and allocate array
    int len = s.readInt();
    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, len);
    Object[] elements = new Object[len];

    // Read in all elements in the proper order.
    for (int i = 0; i < len; i++)
        elements[i] = s.readObject();
    setArray(elements);
}
 
源代码15 项目: openjdk-8   文件: Finalizer.java
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);
            }
        }
    });
}
 
源代码16 项目: jdk8u_jdk   文件: Finalizer.java
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);
            }}});
}
 
源代码17 项目: jdk8u60   文件: SSLSocketImpl.java
private static String getOriginalHostname(InetAddress inetAddress) {
    /*
     * Get the original hostname via sun.misc.SharedSecrets.
     */
    JavaNetAccess jna = SharedSecrets.getJavaNetAccess();
    String originalHostname = jna.getOriginalHostName(inetAddress);

    /*
     * If no application specified hostname, use the IP address.
     */
    if (originalHostname == null || originalHostname.length() == 0) {
        originalHostname = inetAddress.getHostAddress();
    }

    return originalHostname;
}
 
源代码18 项目: JDKSourceCode1.8   文件: IdentityHashMap.java
/**
 * Reconstitutes the <tt>IdentityHashMap</tt> instance from a stream (i.e.,
 * deserializes it).
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException  {
    // Read in any hidden stuff
    s.defaultReadObject();

    // Read in size (number of Mappings)
    int size = s.readInt();
    if (size < 0)
        throw new java.io.StreamCorruptedException
            ("Illegal mappings count: " + size);
    int cap = capacity(size);
    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, cap);
    init(cap);

    // Read the keys and values, and put the mappings in the table
    for (int i=0; i<size; i++) {
        @SuppressWarnings("unchecked")
            K key = (K) s.readObject();
        @SuppressWarnings("unchecked")
            V value = (V) s.readObject();
        putForCreate(key, value);
    }
}
 
源代码19 项目: openjdk-jdk8u   文件: CheckArrayTest.java
/**
 * Test SharedSecrets checkArray with an ObjectInputStream subclassed to
 * handle all input stream functions.
 */
@Test(dataProvider = "Patterns")
public void subclassedOIS(String pattern, int arraySize, Object[] array) throws IOException {
    byte[] bytes = SerialFilterTest.writeObjects(array);
    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         ObjectInputStream ois = new MyInputStream(bais)) {
        // Check the arraysize against the filter
        ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
        ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
        SharedSecrets.getJavaOISAccess()
                .checkArray(ois, array.getClass(), arraySize);
        Assert.assertTrue(array.length >= arraySize,
                "Should have thrown InvalidClassException due to array size");
    } catch (InvalidClassException ice) {
        Assert.assertFalse(array.length > arraySize,
                "Should NOT have thrown InvalidClassException due to array size");
    }
}
 
源代码20 项目: TencentKona-8   文件: Finalizer.java
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);
            }
        }
    });
}
 
源代码21 项目: jdk8u-dev-jdk   文件: Finalizer.java
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);
            }}});
}
 
源代码22 项目: hmftools   文件: ArrayDeck.java
/**
 * Reconstitutes this deque from a stream (that is, deserializes it).
 */
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
    s.defaultReadObject();

    // Read in size and allocate array
    int size = s.readInt();
    int capacity = calculateSize(size);
    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, capacity);
    allocateElements(size);
    head = 0;
    tail = size;

    // Read in all elements in the proper order.
    for (int i = 0; i < size; i++) {
        elements[i] = s.readObject();
    }
}
 
源代码23 项目: JDKSourceCode1.8   文件: ArrayList.java
/**
 * 从流中重构ArrayList实例(即反序列化)。
 */
private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
    elementData = EMPTY_ELEMENTDATA;

    // 执行默认的序列化/反序列化过程
    s.defaultReadObject();

    // 读入数组长度
    s.readInt(); // ignored

    if (size > 0) {
        // 像clone()方法 ,但根据大小而不是容量分配数组
        int capacity = calculateCapacity(elementData, size);
        SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, capacity);
        ensureCapacityInternal(size);

        Object[] a = elementData;
        //读入所有元素
        for (int i = 0; i < size; i++) {
            a[i] = s.readObject();
        }
    }
}
 
源代码24 项目: TencentKona-8   文件: CopyOnWriteArrayList.java
/**
 * Reconstitutes this list from a stream (that is, deserializes it).
 * @param s the stream
 * @throws ClassNotFoundException if the class of a serialized object
 *         could not be found
 * @throws java.io.IOException if an I/O error occurs
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {

    s.defaultReadObject();

    // bind to new lock
    resetLock();

    // Read in array length and allocate array
    int len = s.readInt();
    SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, len);
    Object[] elements = new Object[len];

    // Read in all elements in the proper order.
    for (int i = 0; i < len; i++)
        elements[i] = s.readObject();
    setArray(elements);
}
 
源代码25 项目: TencentKona-8   文件: ArrayList.java
/**
 * Reconstitute the <tt>ArrayList</tt> instance from a stream (that is,
 * deserialize it).
 */
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {
    elementData = EMPTY_ELEMENTDATA;

    // Read in size, and any hidden stuff
    s.defaultReadObject();

    // Read in capacity
    s.readInt(); // ignored

    if (size > 0) {
        // be like clone(), allocate array based upon size not capacity
        int capacity = calculateCapacity(elementData, size);
        SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, capacity);
        ensureCapacityInternal(size);

        Object[] a = elementData;
        // Read in all elements in the proper order.
        for (int i=0; i<size; i++) {
            a[i] = s.readObject();
        }
    }
}
 
源代码26 项目: jdk8u-dev-jdk   文件: FileDispatcherImpl.java
FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException {
    // on Windows we need to keep a handle to the file
    JavaIOFileDescriptorAccess fdAccess =
        SharedSecrets.getJavaIOFileDescriptorAccess();
    FileDescriptor result = new FileDescriptor();
    long handle = duplicateHandle(fdAccess.getHandle(fd));
    fdAccess.setHandle(result, handle);
    return result;
}
 
源代码27 项目: jdk1.8-source-analysis   文件: LogManager.java
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
源代码28 项目: jdk1.8-source-analysis   文件: LogRecord.java
private void inferCaller() {
    needToInferCaller = false;
    JavaLangAccess access = SharedSecrets.getJavaLangAccess();
    Throwable throwable = new Throwable();
    int depth = access.getStackTraceDepth(throwable);

    boolean lookingForLogger = true;
    for (int ix = 0; ix < depth; ix++) {
        // Calling getStackTraceElement directly prevents the VM
        // from paying the cost of building the entire stack frame.
        StackTraceElement frame =
            access.getStackTraceElement(throwable, ix);
        String cname = frame.getClassName();
        boolean isLoggerImpl = isLoggerImplFrame(cname);
        if (lookingForLogger) {
            // Skip all frames until we have found the first logger frame.
            if (isLoggerImpl) {
                lookingForLogger = false;
            }
        } else {
            if (!isLoggerImpl) {
                // skip reflection call
                if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
                   // We've found the relevant frame.
                   setSourceClassName(cname);
                   setSourceMethodName(frame.getMethodName());
                   return;
                }
            }
        }
    }
    // We haven't found a suitable frame, so just punt.  This is
    // OK as we are only committed to making a "best effort" here.
}
 
源代码29 项目: JDKSourceCode1.8   文件: LogRecord.java
private void inferCaller() {
    needToInferCaller = false;
    JavaLangAccess access = SharedSecrets.getJavaLangAccess();
    Throwable throwable = new Throwable();
    int depth = access.getStackTraceDepth(throwable);

    boolean lookingForLogger = true;
    for (int ix = 0; ix < depth; ix++) {
        // Calling getStackTraceElement directly prevents the VM
        // from paying the cost of building the entire stack frame.
        StackTraceElement frame =
            access.getStackTraceElement(throwable, ix);
        String cname = frame.getClassName();
        boolean isLoggerImpl = isLoggerImplFrame(cname);
        if (lookingForLogger) {
            // Skip all frames until we have found the first logger frame.
            if (isLoggerImpl) {
                lookingForLogger = false;
            }
        } else {
            if (!isLoggerImpl) {
                // skip reflection call
                if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
                   // We've found the relevant frame.
                   setSourceClassName(cname);
                   setSourceMethodName(frame.getMethodName());
                   return;
                }
            }
        }
    }
    // We haven't found a suitable frame, so just punt.  This is
    // OK as we are only committed to making a "best effort" here.
}
 
源代码30 项目: openjdk-8   文件: VersionHelper12.java
Thread createThread(final Runnable r) {
    final AccessControlContext acc = AccessController.getContext();
    // 4290486: doPrivileged is needed to create a thread in
    // an environment that restricts "modifyThreadGroup".
    return AccessController.doPrivileged(
            new PrivilegedAction<Thread>() {
                public Thread run() {
                    return SharedSecrets.getJavaLangAccess()
                            .newThreadWithAcc(r, acc);
                }
            }
    );
}