annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java @ 15018:db4254246f9a

Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 07 Apr 2014 16:09:17 -0700
parents 07dd21c7d533
children d708c2fc5cba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
1 /*
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
4 *
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
8 *
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
13 * accompanied this code).
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
14 *
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
18 *
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
21 * questions.
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
22 */
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
23 package com.oracle.graal.hotspot.phases;
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
24
12655
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12573
diff changeset
25 import static com.oracle.graal.nodes.ConstantNode.*;
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12573
diff changeset
26
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
27 import com.oracle.graal.api.meta.*;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14776
diff changeset
28 import com.oracle.graal.hotspot.meta.*;
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
30 import com.oracle.graal.phases.*;
10937
87d9b5518065 Move VerifyUsageWithEquals phases into HighTier.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
31 import com.oracle.graal.phases.tiers.*;
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
32
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14633
diff changeset
33 import edu.umd.cs.findbugs.annotations.*;
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14633
diff changeset
34
10074
e8fbc5fd3440 aot: add/fix some javadoc
Bernhard Urban <bernhard.urban@jku.at>
parents: 10062
diff changeset
35 /**
10421
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
36 * Checks for illegal object constants in a graph processed for AOT compilation. The only legal
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
37 * object constants are {@linkplain String#intern() interned} strings as they will be installed in
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
38 * the Class Data Sharing (CDS) space.
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14633
diff changeset
39 *
10074
e8fbc5fd3440 aot: add/fix some javadoc
Bernhard Urban <bernhard.urban@jku.at>
parents: 10062
diff changeset
40 * @see LoadJavaMirrorWithKlassPhase
e8fbc5fd3440 aot: add/fix some javadoc
Bernhard Urban <bernhard.urban@jku.at>
parents: 10062
diff changeset
41 */
10937
87d9b5518065 Move VerifyUsageWithEquals phases into HighTier.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
42 public class AheadOfTimeVerificationPhase extends VerifyPhase<PhaseContext> {
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
43
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
44 @Override
10937
87d9b5518065 Move VerifyUsageWithEquals phases into HighTier.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
45 protected boolean verify(StructuredGraph graph, PhaseContext context) {
12655
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12573
diff changeset
46 for (ConstantNode node : getConstantNodes(graph)) {
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12573
diff changeset
47 if (node.recordsUsages() || !node.gatherUsages(graph).isEmpty()) {
14166
a0c31f940950 use AssertionError subclass for verification errors found by VerifyPhases
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
48 if (isObject(node) && !isNullReference(node) && !isInternedString(node)) {
a0c31f940950 use AssertionError subclass for verification errors found by VerifyPhases
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
49 throw new VerificationError("illegal object constant: " + node);
a0c31f940950 use AssertionError subclass for verification errors found by VerifyPhases
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
50 }
12573
6332050441eb fixed tests that need to take into account ConstantNodes not recording their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 10937
diff changeset
51 }
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
52 }
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
53 return true;
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
54 }
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
55
10421
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
56 private static boolean isObject(ConstantNode node) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14166
diff changeset
57 return node.getKind() == Kind.Object;
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
58 }
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
59
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
60 private static boolean isNullReference(ConstantNode node) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14776
diff changeset
61 return isObject(node) && node.asConstant().isNull();
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
62 }
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
63
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14633
diff changeset
64 @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "reference equality is what we want")
10421
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
65 private static boolean isInternedString(ConstantNode node) {
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
66 if (!isObject(node)) {
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
67 return false;
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
68 }
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
69
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14776
diff changeset
70 Object o = HotSpotObjectConstant.asObject(node.asConstant());
10421
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
71 if (!(o instanceof String)) {
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
72 return false;
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
73 }
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
74
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
75 String s = (String) o;
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 10074
diff changeset
76 return s == s.intern();
10015
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
77 }
deb5bd841422 aot: add verification phase
Bernhard Urban <bernhard.urban@jku.at>
parents:
diff changeset
78 }