author | dtitov |
Fri, 31 Aug 2018 11:56:43 -0700 | |
changeset 51613 | 3835dc32de5e |
parent 47216 | 71c04702a3d5 |
child 54307 | df62ea1da6ad |
permissions | -rw-r--r-- |
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
1 |
/* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
4 |
* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
8 |
* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
13 |
* accompanied this code). |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
14 |
* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
18 |
* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
21 |
* questions. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
22 |
*/ |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
23 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
24 |
/* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
25 |
* @test ReturnBlobToWrongHeapTest |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
26 |
* @key stress |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
27 |
* @summary Test if VM attempts to return code blobs to an incorrect code heap or to outside of the code cache. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
28 |
* @library /test/lib / |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
29 |
* @modules java.base/jdk.internal.misc |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
30 |
* java.management |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
31 |
* |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
32 |
* @build sun.hotspot.WhiteBox |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
33 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
34 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
35 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
36 |
* -XX:+WhiteBoxAPI |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
37 |
* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
38 |
* -XX:+SegmentedCodeCache |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
39 |
* -XX:ReservedCodeCacheSize=16M |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
40 |
* -XX:CodeCacheMinBlockLength=1 |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
41 |
* compiler.codecache.stress.ReturnBlobToWrongHeapTest |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
42 |
*/ |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
43 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
44 |
package compiler.codecache.stress; |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
45 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
46 |
import sun.hotspot.code.BlobType; |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
47 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
48 |
import java.util.ArrayList; |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
49 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
50 |
public class ReturnBlobToWrongHeapTest { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
51 |
private static final long largeBlobSize = Helper.WHITE_BOX.getUintxVMFlag("ReservedCodeCacheSize") >> 6; |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
52 |
private static final long codeCacheMinBlockLength = Helper.WHITE_BOX.getUintxVMFlag("CodeCacheMinBlockLength"); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
53 |
private static final BlobType[] BLOB_TYPES = BlobType.getAvailable().toArray(new BlobType[0]); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
54 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
55 |
// Allocate blob in first code heap (the code heap with index 0). |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
56 |
private static long allocate(int size) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
57 |
return Helper.WHITE_BOX.allocateCodeBlob(size, BLOB_TYPES[0].id); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
58 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
59 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
60 |
// Free blob. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
61 |
private static void free(long address) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
62 |
Helper.WHITE_BOX.freeCodeBlob(address); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
63 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
64 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
65 |
public static void main(String[] args) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
66 |
if (codeCacheMinBlockLength == 1) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
67 |
// Fill first code heap with large blobs until allocation fails. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
68 |
long address; |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
69 |
while ((address = allocate((int)largeBlobSize)) != 0) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
70 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
71 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
72 |
// Allocate segment-sized blocks in first code heap. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
73 |
long lastSegmentSizedAddress = 0; // Address of the last segment-sized blob allocated |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
74 |
while ((address = allocate(0)) != 0) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
75 |
lastSegmentSizedAddress = address; |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
76 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
77 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
78 |
if (lastSegmentSizedAddress == 0) { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
79 |
throw new RuntimeException("Test failed: Not possible to allocate segment-sized blob"); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
80 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
81 |
|
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
82 |
// Remove last segment-sized block from the first code heap. |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
83 |
free(lastSegmentSizedAddress); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
84 |
} else { |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
85 |
throw new RuntimeException("Test requires CodeCacheMinBlockLength==1; CodeCacheMinBlockLength is " + |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
86 |
codeCacheMinBlockLength); |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
87 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
88 |
} |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
diff
changeset
|
89 |
} |