Mercurial > hg > truffle
comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiVirtualObject.java @ 4199:aaac4894175c
Renamed cri packages from sun to oracle.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 03 Jan 2012 16:29:28 +0100 |
parents | graal/com.oracle.max.cri/src/com/sun/cri/ci/CiVirtualObject.java@de7b3e7ae528 |
children | d89b20486d87 |
comparison
equal
deleted
inserted
replaced
4198:8c9c0e1eaab1 | 4199:aaac4894175c |
---|---|
1 /* | |
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.max.cri.ci; | |
24 | |
25 import com.oracle.max.cri.ri.*; | |
26 | |
27 /** | |
28 * An instance of this class represents an object whose allocation was removed by escape analysis. The information stored in the {@link CiVirtualObject} is used during | |
29 * deoptimization to recreate the object. | |
30 */ | |
31 public final class CiVirtualObject extends CiValue { | |
32 private static final long serialVersionUID = -2907197776426346021L; | |
33 | |
34 private final RiType type; | |
35 private CiValue[] values; | |
36 private final int id; | |
37 | |
38 /** | |
39 * Creates a new CiVirtualObject for the given type, with the given fields. If the type is an instance class then the values array needs to have one entry for each field, ordered in | |
40 * like the fields returned by {@link RiResolvedType#declaredFields()}. If the type is an array then the length of the values array determines the reallocated array length. | |
41 * @param type the type of the object whose allocation was removed during compilation. This can be either an instance of an array type. | |
42 * @param values an array containing all the values to be stored into the object when it is recreated. | |
43 * @param id a unique id that identifies the object within the debug information for one position in the compiled code. | |
44 * @return a new CiVirtualObject instance. | |
45 */ | |
46 public static CiVirtualObject get(RiType type, CiValue[] values, int id) { | |
47 return new CiVirtualObject(type, values, id); | |
48 } | |
49 | |
50 private CiVirtualObject(RiType type, CiValue[] values, int id) { | |
51 super(CiKind.Object); | |
52 this.type = type; | |
53 this.values = values; | |
54 this.id = id; | |
55 } | |
56 | |
57 @Override | |
58 public String toString() { | |
59 return "vobject:" + id; | |
60 } | |
61 | |
62 /** | |
63 * @return the type of the object whose allocation was removed during compilation. This can be either an instance of an array type. | |
64 */ | |
65 public RiType type() { | |
66 return type; | |
67 } | |
68 | |
69 /** | |
70 * @return an array containing all the values to be stored into the object when it is recreated. | |
71 */ | |
72 public CiValue[] values() { | |
73 return values; | |
74 } | |
75 | |
76 /** | |
77 * @return the unique id that identifies the object within the debug information for one position in the compiled code. | |
78 */ | |
79 public int id() { | |
80 return id; | |
81 } | |
82 | |
83 /** | |
84 * Overwrites the current set of values with a new one. | |
85 * @param values an array containing all the values to be stored into the object when it is recreated. | |
86 */ | |
87 public void setValues(CiValue[] values) { | |
88 this.values = values; | |
89 } | |
90 | |
91 @Override | |
92 public int hashCode() { | |
93 return kind.ordinal() + type.hashCode(); | |
94 } | |
95 | |
96 @Override | |
97 public boolean equals(Object o) { | |
98 if (o == this) { | |
99 return true; | |
100 } | |
101 if (o instanceof CiVirtualObject) { | |
102 CiVirtualObject l = (CiVirtualObject) o; | |
103 if (l.type != type || l.values.length != values.length) { | |
104 return false; | |
105 } | |
106 for (int i = 0; i < values.length; i++) { | |
107 if (values[i] != l.values[i]) { | |
108 return false; | |
109 } | |
110 } | |
111 return true; | |
112 } | |
113 return false; | |
114 } | |
115 | |
116 /** | |
117 * This is a helper class used to create virtual objects for a number of different JDK classes. | |
118 */ | |
119 public static class CiVirtualObjectFactory { | |
120 private int nextId = 0; | |
121 private final RiRuntime runtime; | |
122 | |
123 public CiVirtualObjectFactory(RiRuntime runtime) { | |
124 this.runtime = runtime; | |
125 } | |
126 | |
127 public CiVirtualObject constantProxy(CiKind kind, CiValue objectValue, CiValue primitiveValue) { | |
128 CiConstant cKind = CiConstant.forObject(kind); | |
129 // TODO: here the ordering is hard coded... we should query RiType.fields() and act accordingly | |
130 return new CiVirtualObject(runtime.getType(CiConstant.class), new CiValue[] {cKind, primitiveValue, CiValue.IllegalValue, objectValue}, nextId++); | |
131 } | |
132 | |
133 public CiValue proxy(CiValue ciValue) { | |
134 switch (ciValue.kind) { | |
135 case Boolean: | |
136 return new CiVirtualObject(runtime.getType(Boolean.class), new CiValue[] {ciValue}, nextId++); | |
137 case Byte: | |
138 return new CiVirtualObject(runtime.getType(Byte.class), new CiValue[] {ciValue}, nextId++); | |
139 case Char: | |
140 return new CiVirtualObject(runtime.getType(Character.class), new CiValue[] {ciValue}, nextId++); | |
141 case Double: | |
142 return new CiVirtualObject(runtime.getType(Double.class), new CiValue[] {ciValue, CiValue.IllegalValue}, nextId++); | |
143 case Float: | |
144 return new CiVirtualObject(runtime.getType(Float.class), new CiValue[] {ciValue}, nextId++); | |
145 case Int: | |
146 return new CiVirtualObject(runtime.getType(Integer.class), new CiValue[] {ciValue}, nextId++); | |
147 case Long: | |
148 return new CiVirtualObject(runtime.getType(Long.class), new CiValue[] {ciValue, CiValue.IllegalValue}, nextId++); | |
149 case Object: | |
150 return ciValue; | |
151 case Short: | |
152 return new CiVirtualObject(runtime.getType(Short.class), new CiValue[] {ciValue}, nextId++); | |
153 default: | |
154 assert false : ciValue.kind; | |
155 return null; | |
156 } | |
157 } | |
158 | |
159 public CiVirtualObject arrayProxy(RiType arrayType, CiValue[] values) { | |
160 return new CiVirtualObject(arrayType, values, nextId++); | |
161 } | |
162 | |
163 } | |
164 } |