Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/Security/SynchronizedAccess.java
38811 views
/*1* Copyright (c) 1999, 2011, 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 4162583 705491826* @library ../testlibrary27* @summary Make sure Provider api implementations are synchronized properly28*/2930import java.security.*;3132public class SynchronizedAccess {3334public static void main(String[] args) throws Exception {35ProvidersSnapshot snapshot = ProvidersSnapshot.create();36try {37main0(args);38} finally {39snapshot.restore();40}41}4243public static void main0(String[] args) throws Exception {44AccessorThread[] acc = new AccessorThread[200];45for (int i=0; i < acc.length; i++)46acc[i] = new AccessorThread("thread"+i);47for (int i=0; i < acc.length; i++)48acc[i].start();49}50}5152class AccessorThread extends Thread {5354public AccessorThread(String str) {55super(str);56}5758public void run() {59Provider[] provs = new Provider[10];60for (int i=0; i < provs.length; i++)61provs[i] = new MyProvider("name"+i, 1, "test");6263int rounds = 20;64while (rounds-- > 0) {65try {66for (int i=0; i<provs.length; i++) {67Security.addProvider(provs[i]);68}69Signature sig = Signature.getInstance("sigalg");70for (int i=0; i<provs.length; i++) {71Security.removeProvider("name"+i);72}73provs = Security.getProviders();74} catch (NoSuchAlgorithmException nsae) {75}7677try {78Thread.sleep(5);79} catch (InterruptedException ie) {80}81} // while82}83}8485class MyProvider extends Provider {86public MyProvider(String name, double version, String info) {87super(name, version, info);88put("Signature.sigalg", "sigimpl");89}90}919293