Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/AccessController/DoPriv.java
41149 views
1
/*
2
* Copyright (c) 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
/*
25
* @test
26
* @bug 8214583
27
* @summary Check that getContext works after JIT compiler escape analysis.
28
*/
29
import java.security.AccessControlContext;
30
import java.security.AccessController;
31
import java.security.DomainCombiner;
32
import java.security.ProtectionDomain;
33
import java.security.PrivilegedActionException;
34
import java.security.PrivilegedExceptionAction;
35
import java.net.URL;
36
import java.util.Collections;
37
import java.util.HashSet;
38
import java.util.Set;
39
40
public class DoPriv {
41
42
static void go(final DomainCombiner dc0, final AccessControlContext co, final int index) throws Exception {
43
final AccessControlContext ci = new AccessControlContext(co, dc0);
44
AccessController.doPrivileged((PrivilegedExceptionAction<Integer>)() -> {
45
AccessControlContext c1 = AccessController.getContext();
46
DomainCombiner dc = c1.getDomainCombiner();
47
if (dc != dc0 || dc == null) {
48
throw new AssertionError("iteration " + index + " " + dc + " != " + dc0);
49
}
50
return 0;
51
}, ci);
52
}
53
54
public static void main(String[] args) throws Exception {
55
final DomainCombiner dc0 = new DomainCombiner() {
56
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains,
57
ProtectionDomain[] assignedDomains) {
58
return null;
59
}
60
};
61
62
final AccessControlContext co = AccessController.getContext();
63
64
for (int i = 0; i < 500_000; ++i) {
65
go(dc0, co, i);
66
}
67
}
68
}
69
70