1 /*
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.lang.management.ManagementFactory;
25 import java.lang.management.ThreadInfo;
26 import java.security.CodeSource;
27 import java.security.Permission;
28 import java.security.PermissionCollection;
29 import java.security.Permissions;
30 import java.security.Policy;
31 import java.security.ProtectionDomain;
32 import java.util.Enumeration;
33 import java.util.concurrent.Semaphore;
34 import java.util.concurrent.atomic.AtomicBoolean;
35 import java.util.concurrent.atomic.AtomicInteger;
36 import java.util.logging.LogManager;
37 import java.util.logging.Logger;
38 import jdk.internal.misc.JavaAWTAccess;
39 import jdk.internal.misc.SharedSecrets;
40
41 /**
42 * @test
43 * @bug 8065991
44 * @summary check that when LogManager is initialized, a deadlock similar
45 * to that described in 8065709 will not occur.
46 * @modules java.base/jdk.internal.misc
47 * java.logging
48 * java.management
49 * @run main/othervm LogManagerAppContextDeadlock UNSECURE
50 * @run main/othervm LogManagerAppContextDeadlock SECURE
51 *
52 * @author danielfuchs
53 */
54 public class LogManagerAppContextDeadlock {
55
56 public static final Semaphore sem = new Semaphore(0);
57 public static final Semaphore sem2 = new Semaphore(0);
58 public static final Semaphore sem3 = new Semaphore(-2);
59 public static volatile boolean goOn = true;
60 public static volatile Exception thrown;
61
62 // Emulate EventQueue
63 static class FakeEventQueue {
64 static final Logger logger = Logger.getLogger("foo");
65 }
66
332 }
333 public Permissions toPermissions() {
334 final PermissionsBuilder builder = new PermissionsBuilder();
335 builder.addAll(perms);
336 return builder.perms;
337 }
338 }
339
340 // Policy for the test...
341 public static class SimplePolicy extends Policy {
342
343 final Permissions permissions;
344 final Permissions allPermissions;
345 final ThreadLocal<AtomicBoolean> allowAll; // actually: this should be in a thread locale
346 public SimplePolicy(TestCase test, ThreadLocal<AtomicBoolean> allowAll) {
347 this.allowAll = allowAll;
348 // we don't actually need any permission to create our
349 // FileHandlers because we're passing invalid parameters
350 // which will make the creation fail...
351 permissions = new Permissions();
352 permissions.add(new RuntimePermission("accessClassInPackage.jdk.internal.misc"));
353
354 // these are used for configuring the test itself...
355 allPermissions = new Permissions();
356 allPermissions.add(new java.security.AllPermission());
357
358 }
359
360 @Override
361 public boolean implies(ProtectionDomain domain, Permission permission) {
362 if (allowAll.get().get()) return allPermissions.implies(permission);
363 return permissions.implies(permission);
364 }
365
366 @Override
367 public PermissionCollection getPermissions(CodeSource codesource) {
368 return new PermissionsBuilder().addAll(allowAll.get().get()
369 ? allPermissions : permissions).toPermissions();
370 }
371
372 @Override
|
1 /*
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.lang.management.ManagementFactory;
25 import java.lang.management.ThreadInfo;
26 import java.security.CodeSource;
27 import java.security.Permission;
28 import java.security.PermissionCollection;
29 import java.security.Permissions;
30 import java.security.Policy;
31 import java.security.ProtectionDomain;
32 import java.util.Enumeration;
33 import java.util.concurrent.Semaphore;
34 import java.util.concurrent.atomic.AtomicBoolean;
35 import java.util.concurrent.atomic.AtomicInteger;
36 import java.util.logging.LogManager;
37 import java.util.logging.Logger;
38 import jdk.internal.access.JavaAWTAccess;
39 import jdk.internal.access.SharedSecrets;
40
41 /**
42 * @test
43 * @bug 8065991
44 * @summary check that when LogManager is initialized, a deadlock similar
45 * to that described in 8065709 will not occur.
46 * @modules java.base/jdk.internal.access
47 * java.logging
48 * java.management
49 * @run main/othervm LogManagerAppContextDeadlock UNSECURE
50 * @run main/othervm LogManagerAppContextDeadlock SECURE
51 *
52 * @author danielfuchs
53 */
54 public class LogManagerAppContextDeadlock {
55
56 public static final Semaphore sem = new Semaphore(0);
57 public static final Semaphore sem2 = new Semaphore(0);
58 public static final Semaphore sem3 = new Semaphore(-2);
59 public static volatile boolean goOn = true;
60 public static volatile Exception thrown;
61
62 // Emulate EventQueue
63 static class FakeEventQueue {
64 static final Logger logger = Logger.getLogger("foo");
65 }
66
332 }
333 public Permissions toPermissions() {
334 final PermissionsBuilder builder = new PermissionsBuilder();
335 builder.addAll(perms);
336 return builder.perms;
337 }
338 }
339
340 // Policy for the test...
341 public static class SimplePolicy extends Policy {
342
343 final Permissions permissions;
344 final Permissions allPermissions;
345 final ThreadLocal<AtomicBoolean> allowAll; // actually: this should be in a thread locale
346 public SimplePolicy(TestCase test, ThreadLocal<AtomicBoolean> allowAll) {
347 this.allowAll = allowAll;
348 // we don't actually need any permission to create our
349 // FileHandlers because we're passing invalid parameters
350 // which will make the creation fail...
351 permissions = new Permissions();
352 permissions.add(new RuntimePermission("accessClassInPackage.jdk.internal.access"));
353
354 // these are used for configuring the test itself...
355 allPermissions = new Permissions();
356 allPermissions.add(new java.security.AllPermission());
357
358 }
359
360 @Override
361 public boolean implies(ProtectionDomain domain, Permission permission) {
362 if (allowAll.get().get()) return allPermissions.implies(permission);
363 return permissions.implies(permission);
364 }
365
366 @Override
367 public PermissionCollection getPermissions(CodeSource codesource) {
368 return new PermissionsBuilder().addAll(allowAll.get().get()
369 ? allPermissions : permissions).toPermissions();
370 }
371
372 @Override
|