Path: blob/master/test/jdk/java/security/AccessController/DoPriv.java
41149 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 821458326* @summary Check that getContext works after JIT compiler escape analysis.27*/28import java.security.AccessControlContext;29import java.security.AccessController;30import java.security.DomainCombiner;31import java.security.ProtectionDomain;32import java.security.PrivilegedActionException;33import java.security.PrivilegedExceptionAction;34import java.net.URL;35import java.util.Collections;36import java.util.HashSet;37import java.util.Set;3839public class DoPriv {4041static void go(final DomainCombiner dc0, final AccessControlContext co, final int index) throws Exception {42final AccessControlContext ci = new AccessControlContext(co, dc0);43AccessController.doPrivileged((PrivilegedExceptionAction<Integer>)() -> {44AccessControlContext c1 = AccessController.getContext();45DomainCombiner dc = c1.getDomainCombiner();46if (dc != dc0 || dc == null) {47throw new AssertionError("iteration " + index + " " + dc + " != " + dc0);48}49return 0;50}, ci);51}5253public static void main(String[] args) throws Exception {54final DomainCombiner dc0 = new DomainCombiner() {55public ProtectionDomain[] combine(ProtectionDomain[] currentDomains,56ProtectionDomain[] assignedDomains) {57return null;58}59};6061final AccessControlContext co = AccessController.getContext();6263for (int i = 0; i < 500_000; ++i) {64go(dc0, co, i);65}66}67}686970