1 /* 2 * Copyright (c) 2010, 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 /* 26 * @test 27 * @modules java.base/jdk.internal.misc 28 * 29 * @summary converted from VM Testbase vm/mlvm/anonloader/stress/parallelLoad. 30 * VM Testbase keywords: [feature_mlvm, nonconcurrent] 31 * 32 * @library /vmTestbase 33 * /test/lib 34 * @run driver jdk.test.lib.FileInstaller . . 35 * 36 * @comment build test class and indify classes 37 * @build vm.mlvm.anonloader.stress.parallelLoad.Test 38 * @run driver vm.mlvm.share.IndifiedClassesBuilder 39 * 40 * @run main/othervm 41 * -XX:+BytecodeVerificationLocal 42 * vm.mlvm.anonloader.stress.parallelLoad.Test 43 * -threadsPerCpu 4 44 * -threadsExtra 20 45 * -parseTimeout 0 46 * -unsafeLoad true 47 */ 48 49 package vm.mlvm.anonloader.stress.parallelLoad; 50 51 import vm.mlvm.anonloader.share.StressClassLoadingTest; 52 import vm.mlvm.anonloader.share.AnonkTestee01; 53 import vm.mlvm.share.MlvmTestExecutor; 54 import vm.mlvm.share.MultiThreadedTest; 55 import vm.share.FileUtils; 56 57 /** 58 * Verifies that loading classes in parallel from several threads using 59 * {@link sun.misc.Unsafe#defineAnonymousClass} 60 * does not produce exceptions and crashes. 61 * 62 */ 63 public class Test extends MultiThreadedTest { 64 private static final Class<?> HOST_CLASS = AnonkTestee01.class; 65 private static final String NAME_PREFIX = "thread%03d"; 66 67 private final byte[] classBytes; 68 69 private static class SubTest extends StressClassLoadingTest { 70 private final byte[] classBytes; 71 72 public SubTest(byte[] classBytes) { 73 this.classBytes = classBytes; 74 } 75 76 @Override 77 protected Class<?> getHostClass() { 78 return HOST_CLASS; 79 } 80 81 @Override 82 protected byte[] generateClassBytes() { 83 return classBytes; 84 } 85 } 86 87 public Test() throws Exception { 88 classBytes = FileUtils.readClass(HOST_CLASS.getName()); 89 } 90 91 /** 92 * Constructs a sub-test class and runs it. The sub-test class loads 93 * {@link vm.mlvm.anonloader.share.AnonkTestee01} class bytecodes 94 * using {@link sun.misc.Unsafe#defineAnonymousClass} 95 * @param numThread Number of the thread 96 * @throws Exception if there any exceptions thrown in the sub-test 97 */ 98 @Override 99 protected boolean runThread(int numThread) throws Exception { 100 SubTest subTest = new SubTest(classBytes); 101 subTest.setFileNamePrefix(String.format(NAME_PREFIX, numThread)); 102 return subTest.run(); 103 } 104 105 /** 106 * Runs the test. 107 * @param args Test arguments. 108 */ 109 public static void main(String[] args) { 110 MlvmTestExecutor.launch(args); 111 } 112 }