Mercurial > hg > graal-jvmci-8
comparison graal/Runtime/src/com/sun/hotspot/c1x/HotSpotRuntime.java @ 2297:099e697d8934
Renaming c1x4hotspotsrc => graal and HotSpotVM => Runtime
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 22 Apr 2011 15:08:53 +0200 |
parents | |
children | 96ca0e1b8a1d |
comparison
equal
deleted
inserted
replaced
2296:34354e2e40a3 | 2297:099e697d8934 |
---|---|
1 /* | |
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. | |
3 * | |
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product | |
5 * that is described in this document. In particular, and without limitation, these intellectual property | |
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or | |
7 * more additional patents or pending patent applications in the U.S. and in other countries. | |
8 * | |
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun | |
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its | |
11 * supplements. | |
12 * | |
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or | |
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks | |
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the | |
16 * U.S. and other countries. | |
17 * | |
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open | |
19 * Company, Ltd. | |
20 */ | |
21 package com.sun.hotspot.c1x; | |
22 | |
23 import java.io.*; | |
24 import java.lang.reflect.*; | |
25 import java.util.*; | |
26 | |
27 import com.sun.cri.ci.*; | |
28 import com.sun.cri.ci.CiTargetMethod.Call; | |
29 import com.sun.cri.ci.CiTargetMethod.DataPatch; | |
30 import com.sun.cri.ci.CiTargetMethod.Safepoint; | |
31 import com.sun.cri.ri.*; | |
32 import com.sun.max.asm.dis.*; | |
33 import com.sun.max.lang.*; | |
34 | |
35 /** | |
36 * CRI runtime implementation for the HotSpot VM. | |
37 * | |
38 * @author Thomas Wuerthinger, Lukas Stadler | |
39 */ | |
40 public class HotSpotRuntime implements RiRuntime { | |
41 | |
42 final HotSpotVMConfig config; | |
43 final HotSpotRegisterConfig regConfig; | |
44 final HotSpotRegisterConfig globalStubRegConfig; | |
45 private final Compiler compiler; | |
46 | |
47 | |
48 public HotSpotRuntime(HotSpotVMConfig config, Compiler compiler) { | |
49 this.config = config; | |
50 this.compiler = compiler; | |
51 regConfig = new HotSpotRegisterConfig(config, false); | |
52 globalStubRegConfig = new HotSpotRegisterConfig(config, true); | |
53 } | |
54 | |
55 @Override | |
56 public int codeOffset() { | |
57 return 0; | |
58 } | |
59 | |
60 @Override | |
61 public String disassemble(byte[] code, long address) { | |
62 return disassemble(code, new DisassemblyPrinter(false), address); | |
63 } | |
64 | |
65 private String disassemble(byte[] code, DisassemblyPrinter disassemblyPrinter, long address) { | |
66 final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | |
67 final ISA instructionSet = ISA.AMD64; | |
68 Disassembler.disassemble(byteArrayOutputStream, code, instructionSet, WordWidth.BITS_64, address, null, disassemblyPrinter); | |
69 return byteArrayOutputStream.toString(); | |
70 } | |
71 | |
72 @Override | |
73 public String disassemble(final CiTargetMethod targetMethod) { | |
74 | |
75 final DisassemblyPrinter disassemblyPrinter = new DisassemblyPrinter(false) { | |
76 | |
77 private String toString(Call call) { | |
78 if (call.runtimeCall != null) { | |
79 return "{" + call.runtimeCall.name() + "}"; | |
80 } else if (call.symbol != null) { | |
81 return "{" + call.symbol + "}"; | |
82 } else if (call.globalStubID != null) { | |
83 return "{" + call.globalStubID + "}"; | |
84 } else { | |
85 return "{" + call.method + "}"; | |
86 } | |
87 } | |
88 | |
89 private String siteInfo(int pcOffset) { | |
90 for (Call call : targetMethod.directCalls) { | |
91 if (call.pcOffset == pcOffset) { | |
92 return toString(call); | |
93 } | |
94 } | |
95 for (Call call : targetMethod.indirectCalls) { | |
96 if (call.pcOffset == pcOffset) { | |
97 return toString(call); | |
98 } | |
99 } | |
100 for (Safepoint site : targetMethod.safepoints) { | |
101 if (site.pcOffset == pcOffset) { | |
102 return "{safepoint}"; | |
103 } | |
104 } | |
105 for (DataPatch site : targetMethod.dataReferences) { | |
106 if (site.pcOffset == pcOffset) { | |
107 return "{" + site.constant + "}"; | |
108 } | |
109 } | |
110 return null; | |
111 } | |
112 | |
113 @Override | |
114 protected String disassembledObjectString(Disassembler disassembler, DisassembledObject disassembledObject) { | |
115 final String string = super.disassembledObjectString(disassembler, disassembledObject); | |
116 | |
117 String site = siteInfo(disassembledObject.startPosition()); | |
118 if (site != null) { | |
119 return string + " " + site; | |
120 } | |
121 return string; | |
122 } | |
123 }; | |
124 final byte[] code = Arrays.copyOf(targetMethod.targetCode(), targetMethod.targetCodeSize()); | |
125 return disassemble(code, disassemblyPrinter, 0L); | |
126 } | |
127 | |
128 @Override | |
129 public String disassemble(RiMethod method) { | |
130 return "No disassembler available"; | |
131 } | |
132 | |
133 @Override | |
134 public RiConstantPool getConstantPool(RiMethod method) { | |
135 return ((HotSpotTypeResolved) method.holder()).constantPool(); | |
136 } | |
137 | |
138 @Override | |
139 public RiOsrFrame getOsrFrame(RiMethod method, int bci) { | |
140 return null; | |
141 } | |
142 | |
143 @Override | |
144 public RiType getRiType(Class<?> javaClass) { | |
145 assert javaClass != null; | |
146 return compiler.getVMEntries().getType(javaClass); | |
147 } | |
148 | |
149 public Class<?> getJavaClass(CiConstant c) { | |
150 return null; | |
151 } | |
152 | |
153 @Override | |
154 public RiType getRiType(CiKind kind) { | |
155 return getRiType(kind.toJavaClass()); | |
156 } | |
157 | |
158 @Override | |
159 public RiType getRiType(CiConstant constant) { | |
160 return compiler.getVMEntries().getRiType(constant); | |
161 } | |
162 | |
163 @Override | |
164 public boolean isExceptionType(RiType type) { | |
165 return type.isSubtypeOf(getRiType(Throwable.class)); | |
166 } | |
167 | |
168 @Override | |
169 public RiSnippets getSnippets() { | |
170 throw new UnsupportedOperationException("getSnippets"); | |
171 } | |
172 | |
173 @Override | |
174 public boolean mustInline(RiMethod method) { | |
175 return false; | |
176 } | |
177 | |
178 @Override | |
179 public boolean mustNotCompile(RiMethod method) { | |
180 return false; | |
181 } | |
182 | |
183 @Override | |
184 public boolean mustNotInline(RiMethod method) { | |
185 return Modifier.isNative(method.accessFlags()); | |
186 } | |
187 | |
188 @Override | |
189 public Object registerGlobalStub(CiTargetMethod targetMethod, String name) { | |
190 return HotSpotTargetMethod.installStub(compiler, targetMethod, name); | |
191 } | |
192 | |
193 @Override | |
194 public int sizeOfBasicObjectLock() { | |
195 // TODO shouldn't be hard coded | |
196 return 2 * 8; | |
197 } | |
198 | |
199 @Override | |
200 public int basicObjectLockOffsetInBytes() { | |
201 return 8; | |
202 } | |
203 | |
204 @Override | |
205 public RiField getRiField(Field javaField) { | |
206 throw new UnsupportedOperationException("getRiField"); | |
207 } | |
208 | |
209 @Override | |
210 public RiMethod getRiMethod(Method javaMethod) { | |
211 throw new UnsupportedOperationException("getRiMethod"); | |
212 } | |
213 | |
214 @Override | |
215 public RiMethod getRiMethod(Constructor<?> javaConstructor) { | |
216 throw new UnsupportedOperationException("getRiMethod"); | |
217 } | |
218 | |
219 @Override | |
220 public CiConstant invoke(RiMethod method, CiMethodInvokeArguments args) { | |
221 return null; | |
222 } | |
223 | |
224 @Override | |
225 public CiConstant foldWordOperation(int opcode, CiMethodInvokeArguments args) { | |
226 throw new UnsupportedOperationException("foldWordOperation"); | |
227 } | |
228 | |
229 @Override | |
230 public boolean compareConstantObjects(CiConstant x, CiConstant y) { | |
231 return compiler.getVMEntries().compareConstantObjects(x, y); | |
232 } | |
233 | |
234 @Override | |
235 public RiRegisterConfig getRegisterConfig(RiMethod method) { | |
236 return regConfig; | |
237 } | |
238 | |
239 /** | |
240 * HotSpots needs an area suitable for storing a program counter for temporary use during the deoptimization process. | |
241 */ | |
242 @Override | |
243 public int getCustomStackAreaSize() { | |
244 return 8; | |
245 } | |
246 | |
247 @Override | |
248 public boolean supportsArrayIntrinsics() { | |
249 return true; | |
250 } | |
251 | |
252 @Override | |
253 public int getArrayLength(CiConstant array) { | |
254 return compiler.getVMEntries().getArrayLength(array); | |
255 } | |
256 } |