author | zgu |
Thu, 04 Sep 2014 14:50:31 -0400 | |
changeset 26561 | e104c9397ca1 |
parent 24021 | c55dabab1599 |
permissions | -rw-r--r-- |
24021
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
1 |
/* |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
2 |
* Copyright 2014 SAP AG. All Rights Reserved. |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
4 |
* |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
8 |
* |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
13 |
* accompanied this code). |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
14 |
* |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
18 |
* |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
21 |
* questions. |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
22 |
*/ |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
23 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
24 |
/** |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
25 |
* @test |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
26 |
* @bug 8038048 |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
27 |
* @summary assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
28 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+DoEscapeAnalysis -XX:-TieredCompilation -Xbatch TestUnsafePutAddressNullObjMustNotEscape |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
29 |
* @author Richard Reingruber richard DOT reingruber AT sap DOT com |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
30 |
*/ |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
31 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
32 |
import java.lang.reflect.Field; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
33 |
import sun.misc.Unsafe; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
34 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
35 |
public class TestUnsafePutAddressNullObjMustNotEscape { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
36 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
37 |
public static Unsafe usafe; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
38 |
public static long mem; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
39 |
public static long checksum; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
40 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
42 |
System.out.println("EXECUTING test."); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
43 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
44 |
{ |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
45 |
System.out.println("Acquiring sun.misc.Unsafe.theUnsafe using reflection."); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
46 |
getUnsafe(); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
47 |
System.out.println("Allocating raw memory."); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
48 |
mem = (usafe.allocateMemory(1024) + 8L) & ~7L; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
49 |
System.out.println("Triggering JIT compilation of the test method"); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
50 |
triggerJitCompilationOfTestMethod(); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
51 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
52 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
53 |
System.out.println("SUCCESSFULLY passed test."); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
54 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
55 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
56 |
public static void triggerJitCompilationOfTestMethod() { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
57 |
long sum = 0; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
58 |
for (int ii = 50000; ii >= 0; ii--) { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
59 |
sum = testMethod(); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
60 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
61 |
checksum = sum; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
62 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
63 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
64 |
public static class IDGen { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
65 |
private static long id; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
66 |
public long nextId() { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
67 |
return id++; |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
68 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
69 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
70 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
71 |
public static long testMethod() { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
72 |
// dummy alloc to trigger escape analysis |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
73 |
IDGen gen = new IDGen(); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
74 |
// StoreP of null_obj to raw mem triggers assertion in escape analysis |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
75 |
usafe.putAddress(mem, 0L); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
76 |
return gen.nextId(); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
77 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
78 |
|
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
79 |
private static void getUnsafe() throws Exception { |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
80 |
Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
81 |
field.setAccessible(true); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
82 |
usafe = (sun.misc.Unsafe) field.get(null); |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
83 |
} |
c55dabab1599
8038048: assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) runThese -full
kvn
parents:
diff
changeset
|
84 |
} |