408 if (security != null) {
409 g = security.getThreadGroup();
410 }
411
412 /* If the security manager doesn't have a strong opinion
413 on the matter, use the parent thread group. */
414 if (g == null) {
415 g = parent.getThreadGroup();
416 }
417 }
418
419 /* checkAccess regardless of whether or not threadgroup is
420 explicitly passed in. */
421 g.checkAccess();
422
423 /*
424 * Do we have the required permissions?
425 */
426 if (security != null) {
427 if (isCCLOverridden(getClass())) {
428 security.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
429 }
430 }
431
432 g.addUnstarted();
433
434 this.group = g;
435 this.daemon = parent.isDaemon();
436 this.priority = parent.getPriority();
437 if (security == null || isCCLOverridden(parent.getClass()))
438 this.contextClassLoader = parent.getContextClassLoader();
439 else
440 this.contextClassLoader = parent.contextClassLoader;
441 this.inheritedAccessControlContext =
442 acc != null ? acc : AccessController.getContext();
443 this.target = target;
444 setPriority(priority);
445 if (inheritThreadLocals && parent.inheritableThreadLocals != null)
446 this.inheritableThreadLocals =
447 ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);
448 /* Stash the specified stack size in case the VM cares */
1685 if (security != null) {
1686 security.checkPermission(
1687 SecurityConstants.GET_STACK_TRACE_PERMISSION);
1688 security.checkPermission(
1689 SecurityConstants.MODIFY_THREADGROUP_PERMISSION);
1690 }
1691
1692 // Get a snapshot of the list of all threads
1693 Thread[] threads = getThreads();
1694 StackTraceElement[][] traces = dumpThreads(threads);
1695 Map<Thread, StackTraceElement[]> m = new HashMap<>(threads.length);
1696 for (int i = 0; i < threads.length; i++) {
1697 StackTraceElement[] stackTrace = traces[i];
1698 if (stackTrace != null) {
1699 m.put(threads[i], stackTrace);
1700 }
1701 // else terminated so we don't put it in the map
1702 }
1703 return m;
1704 }
1705
1706
1707 private static final RuntimePermission SUBCLASS_IMPLEMENTATION_PERMISSION =
1708 new RuntimePermission("enableContextClassLoaderOverride");
1709
1710 /** cache of subclass security audit results */
1711 /* Replace with ConcurrentReferenceHashMap when/if it appears in a future
1712 * release */
1713 private static class Caches {
1714 /** cache of subclass security audit results */
1715 static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
1716 new ConcurrentHashMap<>();
1717
1718 /** queue for WeakReferences to audited subclasses */
1719 static final ReferenceQueue<Class<?>> subclassAuditsQueue =
1720 new ReferenceQueue<>();
1721 }
1722
1723 /**
1724 * Verifies that this (possibly subclass) instance can be constructed
1725 * without violating security constraints: the subclass must not override
1726 * security-sensitive non-final methods, or else the
1727 * "enableContextClassLoaderOverride" RuntimePermission is checked.
1728 */
|
408 if (security != null) {
409 g = security.getThreadGroup();
410 }
411
412 /* If the security manager doesn't have a strong opinion
413 on the matter, use the parent thread group. */
414 if (g == null) {
415 g = parent.getThreadGroup();
416 }
417 }
418
419 /* checkAccess regardless of whether or not threadgroup is
420 explicitly passed in. */
421 g.checkAccess();
422
423 /*
424 * Do we have the required permissions?
425 */
426 if (security != null) {
427 if (isCCLOverridden(getClass())) {
428 security.checkPermission(
429 SecurityConstants.SUBCLASS_IMPLEMENTATION_PERMISSION);
430 }
431 }
432
433 g.addUnstarted();
434
435 this.group = g;
436 this.daemon = parent.isDaemon();
437 this.priority = parent.getPriority();
438 if (security == null || isCCLOverridden(parent.getClass()))
439 this.contextClassLoader = parent.getContextClassLoader();
440 else
441 this.contextClassLoader = parent.contextClassLoader;
442 this.inheritedAccessControlContext =
443 acc != null ? acc : AccessController.getContext();
444 this.target = target;
445 setPriority(priority);
446 if (inheritThreadLocals && parent.inheritableThreadLocals != null)
447 this.inheritableThreadLocals =
448 ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);
449 /* Stash the specified stack size in case the VM cares */
1686 if (security != null) {
1687 security.checkPermission(
1688 SecurityConstants.GET_STACK_TRACE_PERMISSION);
1689 security.checkPermission(
1690 SecurityConstants.MODIFY_THREADGROUP_PERMISSION);
1691 }
1692
1693 // Get a snapshot of the list of all threads
1694 Thread[] threads = getThreads();
1695 StackTraceElement[][] traces = dumpThreads(threads);
1696 Map<Thread, StackTraceElement[]> m = new HashMap<>(threads.length);
1697 for (int i = 0; i < threads.length; i++) {
1698 StackTraceElement[] stackTrace = traces[i];
1699 if (stackTrace != null) {
1700 m.put(threads[i], stackTrace);
1701 }
1702 // else terminated so we don't put it in the map
1703 }
1704 return m;
1705 }
1706
1707 /** cache of subclass security audit results */
1708 /* Replace with ConcurrentReferenceHashMap when/if it appears in a future
1709 * release */
1710 private static class Caches {
1711 /** cache of subclass security audit results */
1712 static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
1713 new ConcurrentHashMap<>();
1714
1715 /** queue for WeakReferences to audited subclasses */
1716 static final ReferenceQueue<Class<?>> subclassAuditsQueue =
1717 new ReferenceQueue<>();
1718 }
1719
1720 /**
1721 * Verifies that this (possibly subclass) instance can be constructed
1722 * without violating security constraints: the subclass must not override
1723 * security-sensitive non-final methods, or else the
1724 * "enableContextClassLoaderOverride" RuntimePermission is checked.
1725 */
|