annotate graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/DeoptimizeDirectiveTest.java @ 21097:391f94d4d23f

Move MatchProcessor and HotSpotVMConfigPorcessor to their own projects
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Thu, 23 Apr 2015 14:48:52 +0200
parents 2358c0e65b9e
children 48c1ebd24120
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19046
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.api.directives.test;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
25 import org.junit.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
26
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.api.code.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.api.directives.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.compiler.test.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 public class DeoptimizeDirectiveTest extends GraalCompilerTest {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
33
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34 public static boolean inCompiledCode() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35 return GraalDirectives.inCompiledCode();
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
37
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38 @Test
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39 public void testInCompiledCode() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40 ResolvedJavaMethod method = getResolvedJavaMethod("inCompiledCode");
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
41
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
42 Result interpreted = executeExpected(method, null);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
43 assertEquals(new Result(false, null), interpreted);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45 Result compiled = executeActual(method, null);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46 assertEquals(new Result(true, null), compiled);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
48
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 public static boolean deoptimizeSnippet() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 GraalDirectives.deoptimize();
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 return GraalDirectives.inCompiledCode(); // should always return false
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
54 public static boolean deoptimizeAndInvalidateSnippet() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
55 GraalDirectives.deoptimizeAndInvalidate();
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
56 return GraalDirectives.inCompiledCode(); // should always return false
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
57 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
59 @Test
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
60 public void testDeoptimize() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
61 test("deoptimizeSnippet");
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
63
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
64 private boolean testDeoptimizeCheckValid(ResolvedJavaMethod method) {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
65 Result expected = executeExpected(method, null);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
66
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67 InstalledCode code = getCode(method);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68 Result actual;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 try {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70 actual = new Result(code.executeVarargs(), null);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71 } catch (Throwable e) {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
72 actual = new Result(null, e);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
74
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
75 assertEquals(expected, actual);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
76 return code.isValid();
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
79 @Test
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
80 public void testDeoptimizeAndInvalidate() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
81 ResolvedJavaMethod method = getResolvedJavaMethod("deoptimizeAndInvalidateSnippet");
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
82 boolean valid = testDeoptimizeCheckValid(method);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
83 Assert.assertFalse("code should be invalidated", valid);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
84 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
85
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
86 @Test
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
87 public void testDeoptimizeDontInvalidate() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88 ResolvedJavaMethod method = getResolvedJavaMethod("deoptimizeSnippet");
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
89 boolean valid = testDeoptimizeCheckValid(method);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
90 Assert.assertTrue("code should still be valid", valid);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92 }