author | coleenp |
Fri, 20 Jul 2018 18:03:23 -0400 | |
changeset 51221 | b65916c52e3c |
parent 50260 | 46c67f5e27c2 |
child 51269 | b53d1f96b8c4 |
permissions | -rw-r--r-- |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
1 |
/* |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
4 |
* |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
8 |
* |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
13 |
* accompanied this code). |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
14 |
* |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
18 |
* |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
21 |
* questions. |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
22 |
*/ |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
23 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
24 |
//package nsk.jvmti.RedefineClasses.StressRedefine; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
25 |
package nsk.jvmti.RedefineClasses; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
26 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
27 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
28 |
import java.lang.reflect.InvocationTargetException; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
29 |
import java.lang.reflect.Method; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
30 |
import java.net.URL; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
31 |
import java.net.URLClassLoader; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
32 |
import java.util.HashMap; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
33 |
import java.util.LinkedList; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
34 |
import java.util.List; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
35 |
import java.util.Map; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
36 |
import java.util.Random; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
37 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
38 |
import nsk.share.TestFailure; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
39 |
import nsk.share.gc.GCTestBase; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
40 |
import nsk.share.test.ExecutionController; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
41 |
import nsk.share.test.Stresser; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
42 |
import nsk.share.test.Tests; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
43 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
44 |
import vm.share.InMemoryJavaCompiler; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
45 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
46 |
/** |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
47 |
* There is a data structure named "dictionary" in class BlockFreelist. It stores |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
48 |
* information about free memory blocks for further reusing. Allocation of new block goes |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
49 |
* from dictionary only if dictionary is fat enough. (At the moment of test creation this limit is 64K.) |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
50 |
* |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
51 |
* This tests stresses dictionary as other test metaspace/StressDictionary does, but instead of |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
52 |
* failing classloading this test leverages redefineClass method from jvmti. |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
53 |
*/ |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
54 |
public class StressRedefine extends GCTestBase { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
55 |
private static int staticMethodCallersNumber = 10; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
56 |
private static int nonstaticMethodCallersNumber = 10; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
57 |
private static int redefiningThreadsNumber = 40; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
58 |
private static double corruptingBytecodeProbability = .75; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
59 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
60 |
private static volatile Class<?> myClass; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
61 |
private static ExecutionController stresser; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
62 |
private static String[] args; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
63 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
64 |
private static byte[] bytecode; |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
65 |
|
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
66 |
// This is random generator used for generating seeds for other Randoms. Setting seed |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
67 |
// from command line sets seed for this random. |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
68 |
static Random seedGenerator; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
69 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
70 |
static { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
71 |
try { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
72 |
System.loadLibrary("stressRedefine"); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
73 |
} catch (UnsatisfiedLinkError e) { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
74 |
System.err.println("Could not load stressRedefine library"); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
75 |
System.err.println("java.library.path:" + |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
76 |
System.getProperty("java.library.path")); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
77 |
throw e; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
78 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
79 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
80 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
81 |
native static int makeRedefinition(int verbose, Class<?> redefClass, byte[] classBytes); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
82 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
83 |
public static void main(String[] args) { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
84 |
StressRedefine.args = args; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
85 |
Tests.runTest(new StressRedefine(), args); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
86 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
87 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
88 |
@Override |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
89 |
public void run() { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
90 |
seedGenerator = new Random(runParams.getSeed()); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
91 |
GenerateSourceHelper.setRandom(new Random(seedGenerator.nextLong())); |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
92 |
stresser = new Stresser(args); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
93 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
94 |
for (int i = 0; i < args.length; i++ ) { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
95 |
if ("-staticMethodCallersNumber".equals(args[i])) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
96 |
staticMethodCallersNumber = Integer.parseInt(args[i + 1]); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
97 |
} else if ("-nonstaticMethodCallersNumber".equals(args[i])) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
98 |
nonstaticMethodCallersNumber = Integer.parseInt(args[i + 1]); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
99 |
} else if ("-redefiningThreadsNumber".equals(args[i])) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
100 |
redefiningThreadsNumber = Integer.parseInt(args[i + 1]); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
101 |
} else if ("-corruptingBytecodeProbability".equals(args[i])) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
102 |
corruptingBytecodeProbability = Double.parseDouble(args[i + 1]); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
103 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
104 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
105 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
106 |
//Dynamic attach if required |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
107 |
nsk.share.jvmti.JVMTITest.commonInit(args); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
108 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
109 |
new StressRedefine().runIt(); |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
110 |
} |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
111 |
|
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
112 |
private static void runMethod(Random random, String name) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
113 |
while (stresser.continueExecution()) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
114 |
try { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
115 |
// Just for fun we transfer parameters to method |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
116 |
Object res = myClass.getMethod(name, double.class, int.class, Object.class) |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
117 |
.invoke(null, random.nextDouble(), random.nextInt(), new Object()); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
118 |
} catch (IllegalArgumentException | InvocationTargetException |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
119 |
| IllegalAccessException | NoSuchMethodException e) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
120 |
// It's okay to get exception here since we are corrupting bytecode and can't expect |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
121 |
// class to work properly. |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
122 |
System.out.println("Got expected exception: " + e.toString()); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
123 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
124 |
} |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
125 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
126 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
127 |
private static class StaticMethodCaller implements Runnable { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
128 |
private Random random; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
129 |
public StaticMethodCaller() {random = new Random(seedGenerator.nextLong());} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
130 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
131 |
@Override |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
132 |
public void run() { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
133 |
runMethod(random, GenerateSourceHelper.STATIC_METHOD_NAME); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
134 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
135 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
136 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
137 |
private static class NonstaticMethodCaller implements Runnable { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
138 |
private Random random; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
139 |
public NonstaticMethodCaller() {random = new Random(seedGenerator.nextLong());} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
140 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
141 |
@Override |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
142 |
public void run() { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
143 |
runMethod(random, GenerateSourceHelper.NONSTATIC_METHOD_NAME); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
144 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
145 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
146 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
147 |
private static class Worker implements Runnable { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
148 |
private Random random; |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
149 |
public Worker() {random = new Random(seedGenerator.nextLong());} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
150 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
151 |
@Override |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
152 |
public void run() { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
153 |
while (stresser.continueExecution()) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
154 |
byte[] badBytecode = bytecode.clone(); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
155 |
if (random.nextDouble() < corruptingBytecodeProbability) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
156 |
badBytecode[random.nextInt(bytecode.length)] = 42; |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
157 |
} |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
158 |
makeRedefinition(2, myClass, badBytecode); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
159 |
} |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
160 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
161 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
162 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
163 |
private void runIt() { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
164 |
myClass = new DefiningClassLoader().defineClass(generateAndCompile()); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
165 |
stresser.start(0); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
166 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
167 |
// Generate some bytecode. |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
168 |
bytecode = generateAndCompile(); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
169 |
|
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
170 |
List<Thread> threads = new LinkedList<Thread>(); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
171 |
for (int i = 0; i < staticMethodCallersNumber; i++) { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
172 |
threads.add(new Thread(new StaticMethodCaller())); |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
173 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
174 |
for (int i = 0; i < nonstaticMethodCallersNumber; i++) { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
175 |
threads.add(new Thread(new NonstaticMethodCaller())); |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
176 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
177 |
for (int i = 0; i < redefiningThreadsNumber; i++) { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
178 |
threads.add(new Thread(new Worker())); |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
179 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
180 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
181 |
for (Thread thread : threads) { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
182 |
thread.start(); |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
183 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
184 |
for (Thread thread : threads) { |
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
185 |
try { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
186 |
thread.join(); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
187 |
} catch (InterruptedException e) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
188 |
throw new TestFailure("Thread " + Thread.currentThread() + " was interrupted:", e); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
189 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
190 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
191 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
192 |
|
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
193 |
private static byte[] generateAndCompile() { |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
194 |
Map<String, CharSequence> sources = new HashMap<String, CharSequence>(); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
195 |
sources.put(GenerateSourceHelper.CLASS_NAME, GenerateSourceHelper.generateSource()); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
196 |
return InMemoryJavaCompiler.compile(sources).values().iterator().next(); |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
197 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
198 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
199 |
// Auxiliary classloader. Used only once at the beginning. |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
200 |
private static class DefiningClassLoader extends URLClassLoader { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
201 |
public DefiningClassLoader() { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
202 |
super(new URL[0]); |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
203 |
} |
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
204 |
|
51221
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
205 |
Class<?> defineClass(byte[] bytecode) { |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
206 |
return defineClass(null, bytecode, 0, bytecode.length); |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
207 |
} |
b65916c52e3c
8203820: [TESTBUG] vmTestbase/metaspace/staticReferences/StaticReferences.java timed out
coleenp
parents:
50260
diff
changeset
|
208 |
} |
50260
46c67f5e27c2
8199383: [TESTBUG] Open source VM testbase JVMTI tests
iignatyev
parents:
diff
changeset
|
209 |
} |