Mercurial > hg > truffle
comparison graal/Runtime/src/com/sun/hotspot/c1x/VMExitsNative.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 | 4e5515d09314 |
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 | |
22 package com.sun.hotspot.c1x; | |
23 | |
24 import java.io.*; | |
25 import java.util.*; | |
26 | |
27 import com.sun.c1x.debug.*; | |
28 import com.sun.cri.ci.*; | |
29 import com.sun.cri.ri.*; | |
30 import com.sun.hotspot.c1x.logging.*; | |
31 import com.sun.hotspot.c1x.server.*; | |
32 | |
33 /** | |
34 * Exits from the HotSpot VM into Java code. | |
35 * | |
36 * @author Thomas Wuerthinger, Lukas Stadler | |
37 */ | |
38 public class VMExitsNative implements VMExits, Remote { | |
39 | |
40 public static final boolean LogCompiledMethods = false; | |
41 public static boolean compileMethods = true; | |
42 | |
43 private final Compiler compiler; | |
44 | |
45 public final HotSpotTypePrimitive typeBoolean; | |
46 public final HotSpotTypePrimitive typeChar; | |
47 public final HotSpotTypePrimitive typeFloat; | |
48 public final HotSpotTypePrimitive typeDouble; | |
49 public final HotSpotTypePrimitive typeByte; | |
50 public final HotSpotTypePrimitive typeShort; | |
51 public final HotSpotTypePrimitive typeInt; | |
52 public final HotSpotTypePrimitive typeLong; | |
53 public final HotSpotTypePrimitive typeVoid; | |
54 | |
55 public VMExitsNative(Compiler compiler) { | |
56 this.compiler = compiler; | |
57 | |
58 typeBoolean = new HotSpotTypePrimitive(compiler, CiKind.Boolean); | |
59 typeChar = new HotSpotTypePrimitive(compiler, CiKind.Char); | |
60 typeFloat = new HotSpotTypePrimitive(compiler, CiKind.Float); | |
61 typeDouble = new HotSpotTypePrimitive(compiler, CiKind.Double); | |
62 typeByte = new HotSpotTypePrimitive(compiler, CiKind.Byte); | |
63 typeShort = new HotSpotTypePrimitive(compiler, CiKind.Short); | |
64 typeInt = new HotSpotTypePrimitive(compiler, CiKind.Int); | |
65 typeLong = new HotSpotTypePrimitive(compiler, CiKind.Long); | |
66 typeVoid = new HotSpotTypePrimitive(compiler, CiKind.Void); | |
67 } | |
68 | |
69 private static Set<String> compiledMethods = new HashSet<String>(); | |
70 | |
71 @Override | |
72 public void compileMethod(long methodVmId, String name, int entryBCI) throws Throwable { | |
73 | |
74 if (!compileMethods) { | |
75 return; | |
76 } | |
77 | |
78 try { | |
79 HotSpotMethodResolved riMethod = new HotSpotMethodResolved(compiler, methodVmId, name); | |
80 CiResult result = compiler.getCompiler().compileMethod(riMethod, -1, null, null); | |
81 if (LogCompiledMethods) { | |
82 String qualifiedName = CiUtil.toJavaName(riMethod.holder()) + "::" + riMethod.name(); | |
83 compiledMethods.add(qualifiedName); | |
84 } | |
85 | |
86 if (result.bailout() != null) { | |
87 StringWriter out = new StringWriter(); | |
88 result.bailout().printStackTrace(new PrintWriter(out)); | |
89 Throwable cause = result.bailout().getCause(); | |
90 TTY.println("Bailout:\n" + out.toString()); | |
91 if (cause != null) { | |
92 Logger.info("Trace for cause: "); | |
93 for (StackTraceElement e : cause.getStackTrace()) { | |
94 String current = e.getClassName() + "::" + e.getMethodName(); | |
95 String type = ""; | |
96 if (compiledMethods.contains(current)) { | |
97 type = "compiled"; | |
98 } | |
99 Logger.info(String.format("%-10s %3d %s", type, e.getLineNumber(), current)); | |
100 } | |
101 } | |
102 System.out.println("BAILOUT:" + result.bailout().getMessage()); | |
103 String s = result.bailout().getMessage(); | |
104 if (cause != null) { | |
105 s = cause.getMessage(); | |
106 } | |
107 compiler.getVMEntries().recordBailout(s); | |
108 } else { | |
109 HotSpotTargetMethod.installMethod(compiler, riMethod, result.targetMethod()); | |
110 } | |
111 } catch (Throwable t) { | |
112 StringWriter out = new StringWriter(); | |
113 t.printStackTrace(new PrintWriter(out)); | |
114 TTY.println("Compilation interrupted:\n" + out.toString()); | |
115 throw t; | |
116 } | |
117 } | |
118 | |
119 @Override | |
120 public RiMethod createRiMethodResolved(long vmId, String name) { | |
121 return new HotSpotMethodResolved(compiler, vmId, name); | |
122 } | |
123 | |
124 @Override | |
125 public RiMethod createRiMethodUnresolved(String name, String signature, RiType holder) { | |
126 return new HotSpotMethodUnresolved(compiler, name, signature, holder); | |
127 } | |
128 | |
129 @Override | |
130 public RiSignature createRiSignature(String signature) { | |
131 return new HotSpotSignature(compiler, signature); | |
132 } | |
133 | |
134 @Override | |
135 public RiField createRiField(RiType holder, String name, RiType type, int offset) { | |
136 if (offset != -1) { | |
137 HotSpotTypeResolved resolved = (HotSpotTypeResolved) holder; | |
138 return resolved.createRiField(name, type, offset); | |
139 } | |
140 return new HotSpotField(compiler, holder, name, type, offset); | |
141 } | |
142 | |
143 @Override | |
144 public RiType createRiType(long vmId, String name) { | |
145 throw new RuntimeException("not implemented"); | |
146 } | |
147 | |
148 @Override | |
149 public RiType createRiTypePrimitive(int basicType) { | |
150 switch (basicType) { | |
151 case 4: | |
152 return typeBoolean; | |
153 case 5: | |
154 return typeChar; | |
155 case 6: | |
156 return typeFloat; | |
157 case 7: | |
158 return typeDouble; | |
159 case 8: | |
160 return typeByte; | |
161 case 9: | |
162 return typeShort; | |
163 case 10: | |
164 return typeInt; | |
165 case 11: | |
166 return typeLong; | |
167 case 14: | |
168 return typeVoid; | |
169 default: | |
170 throw new IllegalArgumentException("Unknown basic type: " + basicType); | |
171 } | |
172 } | |
173 | |
174 @Override | |
175 public RiType createRiTypeUnresolved(String name) { | |
176 return new HotSpotTypeUnresolved(compiler, name); | |
177 } | |
178 | |
179 @Override | |
180 public RiConstantPool createRiConstantPool(long vmId) { | |
181 return new HotSpotConstantPool(compiler, vmId); | |
182 } | |
183 | |
184 @Override | |
185 public CiConstant createCiConstant(CiKind kind, long value) { | |
186 if (kind == CiKind.Long) { | |
187 return CiConstant.forLong(value); | |
188 } else if (kind == CiKind.Int) { | |
189 return CiConstant.forInt((int) value); | |
190 } else if (kind == CiKind.Short) { | |
191 return CiConstant.forShort((short) value); | |
192 } else if (kind == CiKind.Char) { | |
193 return CiConstant.forChar((char) value); | |
194 } else if (kind == CiKind.Byte) { | |
195 return CiConstant.forByte((byte) value); | |
196 } else if (kind == CiKind.Boolean) { | |
197 return (value == 0) ? CiConstant.FALSE : CiConstant.TRUE; | |
198 } else { | |
199 throw new IllegalArgumentException(); | |
200 } | |
201 } | |
202 | |
203 @Override | |
204 public CiConstant createCiConstantFloat(float value) { | |
205 return CiConstant.forFloat(value); | |
206 } | |
207 | |
208 @Override | |
209 public CiConstant createCiConstantDouble(double value) { | |
210 return CiConstant.forDouble(value); | |
211 } | |
212 | |
213 @Override | |
214 public CiConstant createCiConstantObject(Object object) { | |
215 return CiConstant.forObject(object); | |
216 } | |
217 } |