Mercurial > hg > graal-jvmci-8
annotate test/compiler/jsr292/LongReferenceCastingTest.java @ 24024:649f01d13b2d
8156836: SIGSEGV: Test test/compiler/jsr292/VMAnonymousClasses.java fails with JTREG 4.2 b02
Summary: Need to specify /othervm in annotation section if jvm command line option -Xbatch is specified.
Reviewed-by: kvn
author | shshahma |
---|---|
date | Mon, 27 Jun 2016 11:27:57 +0000 |
parents | 55c8792fe214 |
children |
rev | line source |
---|---|
23810
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
1 /* |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
4 * |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
8 * |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
13 * accompanied this code). |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
14 * |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
18 * |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
21 * questions. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
22 * |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
23 */ |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
24 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
25 import java.lang.invoke.*; |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
26 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
27 /** |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
28 * @test |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
29 * @bug 8148752 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
30 * @summary Test correct casting of MH arguments during inlining. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
31 * @run main LongReferenceCastingTest |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
32 */ |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
33 public class LongReferenceCastingTest { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
34 static final String MY_STRING = "myString"; |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
35 static final MethodHandle MH; |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
36 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
37 static { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
38 try { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
39 MethodHandles.Lookup lookup = MethodHandles.lookup(); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
40 MethodType mt = MethodType.methodType(String.class, long.class, Object.class, String.class); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
41 MH = lookup.findVirtual(LongReferenceCastingTest.class, "myMethod", mt); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
42 } catch (Exception e) { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
43 throw new Error(e); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
44 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
45 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
46 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
47 public String myMethod(long l, Object o, String s) { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
48 // The long argument occupies two stack slots, causing C2 to treat it as |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
49 // two arguments and casting the fist one two long and the second one to Object. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
50 // As a result, Object o is casted to String and the o.toString() call is |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
51 // inlined as String::toString(). We fail at runtime because 'o' is not a String. |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
52 return o.toString(); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
53 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
54 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
55 public String toString() { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
56 return MY_STRING; |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
57 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
58 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
59 public static void main(String[] args) throws Exception { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
60 LongReferenceCastingTest test = new LongReferenceCastingTest(); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
61 try { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
62 for (int i = 0; i < 20_000; ++i) { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
63 if (!test.invoke().equals(MY_STRING)) { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
64 throw new RuntimeException("Invalid string"); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
65 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
66 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
67 } catch (Throwable t) { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
68 throw new RuntimeException("Test failed", t); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
69 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
70 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
71 |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
72 public String invoke() throws Throwable { |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
73 return (String) MH.invokeExact(this, 0L, (Object)this, MY_STRING); |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
74 } |
55c8792fe214
8148752: Compiled StringBuilder code throws StringIndexOutOfBoundsException
thartmann
parents:
diff
changeset
|
75 } |