Path: blob/master/test/jdk/sun/security/x509/AlgorithmId/OidTableInit.java
41153 views
/*1* Copyright (c) 2016 Google Inc. 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 815658426* @modules java.base/sun.security.x50927* @summary AlgorithmId.get initialization thread safety28* @run main/othervm OidTableInit29*/3031import java.util.ArrayList;32import java.util.concurrent.CountDownLatch;33import java.util.concurrent.ExecutorService;34import java.util.concurrent.Executors;35import java.util.concurrent.Future;36import sun.security.x509.AlgorithmId;3738public class OidTableInit {39public static void main(String[] args) throws Throwable {40final String[] algorithmNames = {41"PBKDF2WITHHMACSHA1",42"PBEWITHMD5ANDDES",43"DSA",44"SHA384WITHRSA",45"RSA",46"SHA1WITHDSA",47"SHA512WITHRSA",48"MD2WITHRSA",49"PBEWITHSHA1ANDDESEDE",50"SHA1WITHRSA",51"DIFFIEHELLMAN",52"MD5WITHRSA",53"PBEWITHSHA1ANDRC2_40",54"SHA256WITHRSA",55};5657final int THREADS = 2;58final ExecutorService pool = Executors.newFixedThreadPool(THREADS);59final CountDownLatch startingGate = new CountDownLatch(THREADS);60final Runnable r = new Runnable() { public void run() {61startingGate.countDown();62do {} while (startingGate.getCount() > 0);63try {64for (String algorithmName : algorithmNames)65AlgorithmId.get(algorithmName);66} catch (Throwable fail) {67throw new AssertionError(fail);68}69}};70final ArrayList<Future<?>> futures = new ArrayList<>();71for (int i = 0; i < THREADS; i++)72futures.add(pool.submit(r));73pool.shutdown();74for (Future<?> future : futures) future.get();75}76}777879