annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LIRKind.java @ 19411:b029f5244371

Eclipse format.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 18:08:55 +0100
parents c88ab4f1f04a
children a4b60873851b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.api.meta;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
25 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
26 * Represents the type of values in the LIR. It is composed of a {@link PlatformKind} that gives the
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27 * low level representation of the value, and a {@link #referenceMask} that describes the location
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28 * of object references in the value.
16347
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
29 *
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
30 * <h2>Constructing {@link LIRKind} instances</h2>
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
31 *
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
32 * During LIR generation, every new {@link Value} should get a {@link LIRKind} of the correct
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
33 * {@link PlatformKind} that also contains the correct reference information. {@linkplain LIRKind
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
34 * LIRKinds} should be created as follows:
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
35 *
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
36 * <p>
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
37 * If the result value is created from one or more input values, the {@link LIRKind} should be
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
38 * created with {@link LIRKind#derive}(inputs). If the result has a different {@link PlatformKind}
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
39 * than the inputs, {@link LIRKind#derive}(inputs).{@link #changeType}(resultKind) should be used.
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
40 * <p>
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
41 * If the result is an exact copy of one of the inputs, {@link Value#getLIRKind()} can be used. Note
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
42 * that this is only correct for move-like operations, like conditional move or compare-and-swap.
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
43 * For convert operations, {@link LIRKind#derive} should be used.
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
44 * <p>
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
45 * If it is known that the result will be a reference (e.g. pointer arithmetic where the end result
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
46 * is a valid oop), {@link LIRKind#reference} should be used.
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
47 * <p>
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
48 * If it is known that the result will neither be a reference nor be derived from a reference,
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
49 * {@link LIRKind#value} can be used. If the operation producing this value has inputs, this is very
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
50 * likely wrong, and {@link LIRKind#derive} should be used instead.
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
51 * <p>
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
52 * If it is known that the result is derived from a reference, {@link LIRKind#derivedReference} can
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
53 * be used. In most cases, {@link LIRKind#derive} should be used instead, since it is able to detect
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
54 * this automatically.
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
55 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
56 public final class LIRKind {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
57
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
59 * The non-type. This uses {@link #derivedReference}, so it can never be part of an oop map.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
60 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
61 public static final LIRKind Illegal = derivedReference(Kind.Illegal);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
63 private final PlatformKind platformKind;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
64 private final int referenceMask;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
65
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
66 private static final int DERIVED_REFERENCE = -1;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68 private LIRKind(PlatformKind platformKind, int referenceMask) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 this.platformKind = platformKind;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70 this.referenceMask = referenceMask;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
72
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73 /**
16347
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
74 * Create a {@link LIRKind} of type {@code platformKind} that contains a primitive value. Should
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
75 * be only used when it's guaranteed that the value is not even indirectly derived from a
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
76 * reference. Otherwise, {@link #derive(Value...)} should be used instead.
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78 public static LIRKind value(PlatformKind platformKind) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
79 assert platformKind != Kind.Object : "Object should always be used as reference type";
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
80 return new LIRKind(platformKind, 0);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
81 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
82
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
83 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
84 * Create a {@link LIRKind} of type {@code platformKind} that contains a single tracked oop
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
85 * reference.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
86 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
87 public static LIRKind reference(PlatformKind platformKind) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88 int length = platformKind.getVectorLength();
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
89 assert 0 < length && length < 32 : "vector of " + length + " references not supported";
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
90 return new LIRKind(platformKind, (1 << length) - 1);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
93 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
94 * Create a {@link LIRKind} of type {@code platformKind} that contains a value that is derived
16347
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
95 * from a reference. Values of this {@link LIRKind} can not be live at safepoints. In most
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
96 * cases, this should not be called directly. {@link #derive} should be used instead to
c6a1215d025b Improve documentation of LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16346
diff changeset
97 * automatically propagate this information.
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
98 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
99 public static LIRKind derivedReference(PlatformKind platformKind) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
100 return new LIRKind(platformKind, DERIVED_REFERENCE);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
101 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
102
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
103 /**
16346
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
104 * Derive a new type from inputs. The result will have the {@link PlatformKind} of one of the
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
105 * inputs. If all inputs are values, the result is a value. Otherwise, the result is a derived
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
106 * reference.
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
107 *
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
108 * This method should be used to construct the result {@link LIRKind} of any operation that
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
109 * modifies values (e.g. arithmetics).
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
110 */
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
111 public static LIRKind derive(Value... inputs) {
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
112 assert inputs.length > 0;
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
113 for (Value input : inputs) {
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
114 LIRKind kind = input.getLIRKind();
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
115 if (kind.isDerivedReference()) {
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
116 return kind;
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
117 } else if (!kind.isValue()) {
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
118 return kind.makeDerivedReference();
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
119 }
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
120 }
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
121
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
122 // all inputs are values, just return one of them
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
123 return inputs[0].getLIRKind();
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
124 }
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
125
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
126 /**
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
127 * Create a new {@link LIRKind} with the same reference information and a new
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
128 * {@linkplain #getPlatformKind platform kind}. If the new kind is a longer vector than this,
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
129 * the new elements are marked as untracked values.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
130 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
131 public LIRKind changeType(PlatformKind newPlatformKind) {
16346
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
132 if (newPlatformKind == platformKind) {
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
133 return this;
bbf051d717f5 Propagate reference information through arithmetics.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
134 } else if (isDerivedReference()) {
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
135 return derivedReference(newPlatformKind);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
136 } else if (referenceMask == 0) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
137 // value type
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
138 return new LIRKind(newPlatformKind, 0);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
139 } else {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
140 // reference type
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
141 int newLength = Math.min(32, newPlatformKind.getVectorLength());
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
142 int newReferenceMask = referenceMask & (0xFFFFFFFF >>> (32 - newLength));
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
143 assert newReferenceMask != DERIVED_REFERENCE;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
144 return new LIRKind(newPlatformKind, newReferenceMask);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
145 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
146 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
147
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
148 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
149 * Create a new {@link LIRKind} with a new {@linkplain #getPlatformKind platform kind}. If the
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
150 * new kind is longer than this, the reference positions are repeated to fill the vector.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
151 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
152 public LIRKind repeat(PlatformKind newPlatformKind) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
153 if (isDerivedReference()) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
154 return derivedReference(newPlatformKind);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
155 } else if (referenceMask == 0) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
156 // value type
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
157 return new LIRKind(newPlatformKind, 0);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
158 } else {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
159 // reference type
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
160 int oldLength = platformKind.getVectorLength();
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
161 int newLength = newPlatformKind.getVectorLength();
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
162 assert oldLength <= newLength && newLength < 32 && (newLength % oldLength) == 0;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
163
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
164 // repeat reference mask to fill new kind
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
165 int newReferenceMask = 0;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
166 for (int i = 0; i < newLength; i += platformKind.getVectorLength()) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
167 newReferenceMask |= referenceMask << i;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
168 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
169
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
170 assert newReferenceMask != DERIVED_REFERENCE;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
171 return new LIRKind(newPlatformKind, newReferenceMask);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
172 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
173 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
174
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
175 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
176 * Create a new {@link LIRKind} with the same type, but marked as containing a derivedReference.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
177 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
178 public LIRKind makeDerivedReference() {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
179 return new LIRKind(platformKind, DERIVED_REFERENCE);
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
180 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
181
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
182 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
183 * Get the low level type that is used in code generation.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
184 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
185 public PlatformKind getPlatformKind() {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
186 return platformKind;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
187 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
188
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
189 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
190 * Check whether this value is derived from a reference. If this returns {@code true}, this
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
191 * value must not be live at safepoints.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
192 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
193 public boolean isDerivedReference() {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
194 return referenceMask == DERIVED_REFERENCE;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
195 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
196
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
197 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
198 * Check whether the {@code idx}th part of this value is a reference that must be tracked at
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
199 * safepoints.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
200 *
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
201 * @param idx The index into the vector if this is a vector kind. Must be 0 if this is a scalar
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
202 * kind.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
203 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
204 public boolean isReference(int idx) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
205 assert 0 <= idx && idx < platformKind.getVectorLength() : "invalid index " + idx + " in " + this;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
206 return !isDerivedReference() && (referenceMask & 1 << idx) != 0;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
207 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
208
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
209 /**
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
210 * Check whether this kind is a value type that doesn't need to be tracked at safepoints.
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
211 */
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
212 public boolean isValue() {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
213 return referenceMask == 0;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
214 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
215
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
216 @Override
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
217 public String toString() {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
218 if (isValue()) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
219 return platformKind.name();
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
220 } else if (isDerivedReference()) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
221 return platformKind.name() + "[*]";
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
222 } else {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
223 StringBuilder ret = new StringBuilder();
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
224 ret.append(platformKind.name());
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
225 ret.append('[');
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
226 for (int i = 0; i < platformKind.getVectorLength(); i++) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
227 if (isReference(i)) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
228 ret.append('.');
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
229 } else {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
230 ret.append(' ');
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
231 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
232 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
233 ret.append(']');
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
234 return ret.toString();
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
235 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
236 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
237
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
238 @Override
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
239 public int hashCode() {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
240 final int prime = 31;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
241 int result = 1;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
242 result = prime * result + ((platformKind == null) ? 0 : platformKind.hashCode());
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
243 result = prime * result + referenceMask;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
244 return result;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
245 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
246
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
247 @Override
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
248 public boolean equals(Object obj) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
249 if (this == obj) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
250 return true;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
251 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
252 if (!(obj instanceof LIRKind)) {
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
253 return false;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
254 }
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
255
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
256 LIRKind other = (LIRKind) obj;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
257 return platformKind == other.platformKind && referenceMask == other.referenceMask;
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
258 }
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 16347
diff changeset
259 }