author | coleenp |
Fri, 20 Jul 2018 18:03:23 -0400 | |
changeset 51221 | b65916c52e3c |
parent 50223 | 28a33a0dbf04 |
child 52273 | 97b761e247b3 |
permissions | -rw-r--r-- |
50223
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
1 |
/* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
4 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
8 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
13 |
* accompanied this code). |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
14 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
18 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
21 |
* questions. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
22 |
*/ |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
23 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
24 |
/* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
25 |
* @test |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
26 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
27 |
* @summary converted from VM Testbase metaspace/stressDictionary. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
28 |
* VM Testbase keywords: [nonconcurrent, javac] |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
29 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
30 |
* @library /vmTestbase /test/lib |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
31 |
* @run driver jdk.test.lib.FileInstaller . . |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
32 |
* @run main/othervm metaspace.stressDictionary.StressDictionary -stressTime 30 |
50223
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
33 |
*/ |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
34 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
35 |
package metaspace.stressDictionary; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
36 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
37 |
import java.util.*; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
38 |
import java.lang.management.ManagementFactory; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
39 |
import java.lang.reflect.InvocationTargetException; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
40 |
import java.lang.reflect.Method; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
41 |
import java.util.concurrent.*; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
42 |
import java.util.concurrent.atomic.AtomicLong; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
43 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
44 |
import nsk.share.gc.GCTestBase; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
45 |
import nsk.share.test.*; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
46 |
import vm.share.InMemoryJavaCompiler; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
47 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
48 |
/** |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
49 |
* There is a data structure named "dictionary" in class BlockFreelist. It stores |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
50 |
* information about free memory blocks for further reusing. Allocation of new block goes |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
51 |
* from dictionary only if dictionary is fat enough. (At the moment of test creation this limit is 64K.) |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
52 |
* So to stress dictionary we should fill it permanently. The easiest way to fill the dictionary |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
53 |
* is to fail class loading. This failed action will return allocated blocks to dictionary. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
54 |
* |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
55 |
* There are two type of threads in this test: threads, failing classloading and threads, |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
56 |
* loading regular classes and checking they work properly. |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
57 |
*/ |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
58 |
public class StressDictionary extends GCTestBase { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
59 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
60 |
private static byte[] bytecode; |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
61 |
|
50223
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
62 |
private class FillingDictionaryWorker implements Callable<Object> { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
63 |
@Override |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
64 |
public Object call() throws Exception { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
65 |
while (stresser.continueExecution()) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
66 |
try { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
67 |
byte[] badBytecode = bytecode.clone(); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
68 |
badBytecode[random.nextInt(badBytecode.length)] = (byte) 42; |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
69 |
classloader.define(badBytecode); |
50223
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
70 |
} catch (Throwable e) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
71 |
// We can get ClassFormatError, ClassNotFoundException or anything else here |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
72 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
73 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
74 |
return null; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
75 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
76 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
77 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
78 |
private class RegularWorker implements Callable<Object> { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
79 |
@Override |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
80 |
public Object call() throws Exception { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
81 |
while (stresser.continueExecution()) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
82 |
Class<?> c = classloader.define(bytecode); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
83 |
testClass(c); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
84 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
85 |
return null; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
86 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
87 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
88 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
89 |
private static String[] args; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
90 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
91 |
private static final String methodName = "myMethod"; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
92 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
93 |
private static final int NUMBER_OF_CORRUPTING_THREADS = 10; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
94 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
95 |
private static final int NUMBER_OF_METHOD_CALLS = 50; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
96 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
97 |
private static final int NUMBER_OF_NOT_CORRUPTING_THREADS = 10; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
98 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
99 |
private AtomicLong classesCounter = new AtomicLong(0); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
100 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
101 |
private volatile ClassloaderUnderTest classloader = new ClassloaderUnderTest(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
102 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
103 |
private Random random; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
104 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
105 |
private ExecutionController stresser; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
106 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
107 |
public static void main(String[] args) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
108 |
StressDictionary.args = args; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
109 |
Tests.runTest(new StressDictionary(), args); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
110 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
111 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
112 |
public void run() { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
113 |
random = new Random(runParams.getSeed()); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
114 |
stresser = new Stresser(args); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
115 |
stresser.start(1); |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
116 |
// Generate some bytecodes. |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50223
diff
changeset
|
117 |
bytecode = generateAndCompile(); |
50223
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
118 |
List<Callable<Object>> tasks = new LinkedList<Callable<Object>>(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
119 |
for (int i = 0; i < NUMBER_OF_CORRUPTING_THREADS; i++) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
120 |
tasks.add(this.new FillingDictionaryWorker()); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
121 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
122 |
for (int i = 0; i < NUMBER_OF_NOT_CORRUPTING_THREADS; i++) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
123 |
tasks.add(this.new RegularWorker()); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
124 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
125 |
ExecutorService executorService = Executors.newCachedThreadPool(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
126 |
try { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
127 |
executorService.invokeAll(tasks); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
128 |
} catch (InterruptedException e) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
129 |
e.printStackTrace(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
130 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
131 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
132 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
133 |
private byte[] generateAndCompile() { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
134 |
Map<String, CharSequence> sources = new HashMap<String, CharSequence>(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
135 |
String className = "MyClass" + classesCounter.incrementAndGet(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
136 |
sources.put(className, generateSource(className)); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
137 |
return InMemoryJavaCompiler.compile(sources).values().iterator().next(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
138 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
139 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
140 |
private CharSequence generateSource(String className) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
141 |
return "public class " + className + " { " + |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
142 |
"public static String s1 = \"s1" + random.nextInt() + "\"; " + |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
143 |
"public String s2 = \"s2" + random.nextInt() + "\"; " + |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
144 |
"public String " + methodName + "() {return s1 + s2; } " + |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
145 |
"}"; |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
146 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
147 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
148 |
private void testClass(Class<?> clazz) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
149 |
try { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
150 |
for (Method m : clazz.getMethods()) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
151 |
if (m.getName().equals(methodName)) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
152 |
for (int j = 0; j < NUMBER_OF_METHOD_CALLS; j++) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
153 |
m.invoke(clazz.newInstance()); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
154 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
155 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
156 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
157 |
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
158 |
log.error("Class check failed: " + e.getMessage()); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
159 |
e.printStackTrace(); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
160 |
setFailed(true); |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
161 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
162 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
163 |
} |
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
164 |
|
28a33a0dbf04
8199257: [TESTBUG] Open source VM testbase metaspace tests
mseledtsov
parents:
diff
changeset
|
165 |
} |