Mercurial > hg > graal-compiler
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java @ 1422:3483ec571caf
* using reflected objects instead of oops
* removed scratch from allocatable registers
* instanceof xir snippet
* arraylength xir snippet
* exceptionobject xir snippet
* VMEntries and VMExits as interfaces
* calls to VMEntries and VMExits are routet through logging proxies
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 02 Aug 2010 15:44:38 -0700 |
parents | 6223633ce7dd |
children | 760213a60e8b |
comparison
equal
deleted
inserted
replaced
1421:6223633ce7dd | 1422:3483ec571caf |
---|---|
44 | 44 |
45 private XirTemplate[] emptyTemplates = new XirTemplate[CiKind.values().length]; | 45 private XirTemplate[] emptyTemplates = new XirTemplate[CiKind.values().length]; |
46 private XirTemplate prologueTemplate; | 46 private XirTemplate prologueTemplate; |
47 private XirTemplate staticPrologueTemplate; | 47 private XirTemplate staticPrologueTemplate; |
48 private XirTemplate epilogueTemplate; | 48 private XirTemplate epilogueTemplate; |
49 private XirTemplate arrayLengthTemplate; | |
50 private XirTemplate exceptionObjectTemplate; | |
49 | 51 |
50 static class XirPair { | 52 static class XirPair { |
51 | 53 |
52 final XirTemplate resolved; | 54 final XirTemplate resolved; |
53 final XirTemplate unresolved; | 55 final XirTemplate unresolved; |
106 templates.add(emptyTemplates[index]); | 108 templates.add(emptyTemplates[index]); |
107 } | 109 } |
108 prologueTemplate = buildPrologue(false); | 110 prologueTemplate = buildPrologue(false); |
109 staticPrologueTemplate = buildPrologue(true); | 111 staticPrologueTemplate = buildPrologue(true); |
110 epilogueTemplate = buildEpilogue(); | 112 epilogueTemplate = buildEpilogue(); |
113 arrayLengthTemplate = buildArrayLength(); | |
114 exceptionObjectTemplate = buildExceptionObject(); | |
111 instanceofTemplate = buildInstanceof(false); | 115 instanceofTemplate = buildInstanceof(false); |
112 instanceofTemplateNonnull = buildInstanceof(true); | 116 instanceofTemplateNonnull = buildInstanceof(true); |
113 | 117 |
114 return templates; | 118 return templates; |
115 } | 119 } |
116 | 120 |
117 private XirTemplate buildPrologue(boolean staticMethod) { | 121 private XirTemplate buildPrologue(boolean staticMethod) { |
118 asm.restart(CiKind.Void); | 122 asm.restart(CiKind.Void); |
119 XirOperand sp = asm.createRegister("stack pointer", CiKind.Word, registerConfig.getStackPointerRegister()); | 123 XirOperand sp = asm.createRegister("stack pointer", CiKind.Word, registerConfig.getStackPointerRegister()); |
120 XirOperand temp = asm.createRegister("temp (rax)", CiKind.Word, AMD64.rax); | 124 XirOperand temp = asm.createRegister("temp (rax)", CiKind.Int, AMD64.rax); |
121 | 125 |
122 asm.align(config.codeEntryAlignment); | 126 asm.align(config.codeEntryAlignment); |
123 asm.entrypoint(HotSpotRuntime.Entrypoints.UNVERIFIED); | 127 asm.entrypoint(HotSpotRuntime.Entrypoints.UNVERIFIED); |
124 if (!staticMethod) { | 128 if (!staticMethod) { |
125 // TODO do some checking... | 129 // TODO do some checking... |
129 | 133 |
130 asm.align(config.codeEntryAlignment); | 134 asm.align(config.codeEntryAlignment); |
131 } | 135 } |
132 asm.entrypoint(HotSpotRuntime.Entrypoints.VERIFIED); | 136 asm.entrypoint(HotSpotRuntime.Entrypoints.VERIFIED); |
133 // stack banging | 137 // stack banging |
134 asm.pload(CiKind.Word, temp, sp, asm.i(-config.stackShadowPages * config.vmPageSize), true); | 138 asm.pstore(CiKind.Word, sp, asm.i(-config.stackShadowPages * config.vmPageSize), temp, true); |
135 asm.pushFrame(); | 139 asm.pushFrame(); |
136 | 140 |
137 return asm.finishTemplate(staticMethod ? "static prologue" : "prologue"); | 141 return asm.finishTemplate(staticMethod ? "static prologue" : "prologue"); |
138 } | 142 } |
139 | 143 |
140 private XirTemplate buildEpilogue() { | 144 private XirTemplate buildEpilogue() { |
141 asm.restart(CiKind.Void); | 145 asm.restart(CiKind.Void); |
142 asm.popFrame(); | 146 asm.popFrame(); |
143 // TODO safepoint check | 147 // TODO safepoint check |
144 return asm.finishTemplate("epilogue"); | 148 return asm.finishTemplate("epilogue"); |
149 } | |
150 | |
151 private XirTemplate buildArrayLength() { | |
152 XirOperand result = asm.restart(CiKind.Int); | |
153 XirParameter object = asm.createInputParameter("object", CiKind.Object); | |
154 asm.pload(CiKind.Int, result, object, asm.i(config.arrayLengthOffset), true); | |
155 return asm.finishTemplate("arrayLength"); | |
156 } | |
157 | |
158 private XirTemplate buildExceptionObject() { | |
159 asm.restart(); | |
160 XirOperand temp = asm.createRegister("temp (rax)", CiKind.Object, AMD64.rax); | |
161 return asm.finishTemplate(temp, "exception object"); | |
145 } | 162 } |
146 | 163 |
147 private XirPair buildGetFieldTemplate(CiKind kind, boolean isStatic) { | 164 private XirPair buildGetFieldTemplate(CiKind kind, boolean isStatic) { |
148 final XirTemplate resolved; | 165 final XirTemplate resolved; |
149 final XirTemplate unresolved; | 166 final XirTemplate unresolved; |
211 private XirPair buildInstanceof(boolean nonnull) { | 228 private XirPair buildInstanceof(boolean nonnull) { |
212 XirTemplate resolved; | 229 XirTemplate resolved; |
213 XirTemplate unresolved; | 230 XirTemplate unresolved; |
214 { | 231 { |
215 XirOperand result = asm.restart(CiKind.Boolean); | 232 XirOperand result = asm.restart(CiKind.Boolean); |
216 asm.callRuntime(config.instanceofStub, result); | |
217 | 233 |
218 XirParameter object = asm.createInputParameter("object", CiKind.Object); | 234 XirParameter object = asm.createInputParameter("object", CiKind.Object); |
219 XirParameter hub = asm.createConstantInputParameter("hub", CiKind.Object); | 235 XirParameter hub = asm.createConstantInputParameter("hub", CiKind.Object); |
220 XirOperand temp = asm.createTemp("temp", CiKind.Object); | 236 XirOperand temp = asm.createTemp("temp", CiKind.Object); |
221 XirLabel pass = asm.createInlineLabel("pass"); | 237 XirLabel end = asm.createInlineLabel("end"); |
222 XirLabel fail = asm.createInlineLabel("fail"); | 238 XirLabel slow_path = asm.createOutOfLineLabel("slow path"); |
239 | |
223 asm.mov(result, asm.b(false)); | 240 asm.mov(result, asm.b(false)); |
224 if (!nonnull) { | 241 if (!nonnull) { |
225 // first check for null | 242 // first check for null |
226 asm.jeq(fail, object, asm.o(null)); | 243 asm.jeq(end, object, asm.o(null)); |
227 } | 244 } |
228 asm.pload(CiKind.Object, temp, object, asm.i(config.hubOffset), !nonnull); | 245 asm.pload(CiKind.Object, temp, object, asm.i(config.hubOffset), !nonnull); |
229 asm.jneq(fail, temp, hub); | |
230 asm.bindInline(pass); | |
231 asm.mov(result, asm.b(true)); | 246 asm.mov(result, asm.b(true)); |
232 asm.bindInline(fail); | 247 asm.jneq(slow_path, temp, hub); |
248 | |
249 asm.bindInline(end); | |
250 | |
251 asm.bindOutOfLine(slow_path); | |
252 asm.push(temp); | |
253 asm.push(hub); | |
254 asm.callRuntime(config.instanceofStub, result); | |
255 asm.pop(hub); | |
256 asm.pop(result); | |
257 asm.jmp(end); | |
233 resolved = asm.finishTemplate("instanceof-leaf<" + nonnull + ">"); | 258 resolved = asm.finishTemplate("instanceof-leaf<" + nonnull + ">"); |
234 } | 259 } |
235 {/* | 260 {/* |
236 * // unresolved instanceof unresolved = buildUnresolvedInstanceOf(nonnull); | 261 * // unresolved instanceof unresolved = buildUnresolvedInstanceOf(nonnull); |
237 */ | 262 */ |
238 asm.restart(CiKind.Boolean); | 263 asm.restart(CiKind.Boolean); |
264 XirParameter object = asm.createInputParameter("object", CiKind.Object); | |
239 asm.shouldNotReachHere(); | 265 asm.shouldNotReachHere(); |
240 unresolved = asm.finishTemplate("instanceof-leaf<" + nonnull + ">"); | 266 unresolved = asm.finishTemplate("instanceof-leaf<" + nonnull + ">"); |
241 } | 267 } |
242 return new XirPair(resolved, unresolved); | 268 return new XirPair(resolved, unresolved); |
243 } | 269 } |
244 | 270 |
245 @Override | 271 @Override |
246 public XirSnippet genArrayLength(XirSite site, XirArgument array) { | 272 public XirSnippet genArrayLength(XirSite site, XirArgument array) { |
247 return new XirSnippet(emptyTemplates[CiKind.Int.ordinal()]); | 273 return new XirSnippet(arrayLengthTemplate, array); |
248 } | 274 } |
249 | 275 |
250 @Override | 276 @Override |
251 public XirSnippet genArrayLoad(XirSite site, XirArgument array, XirArgument index, XirArgument length, CiKind elementKind, RiType elementType) { | 277 public XirSnippet genArrayLoad(XirSite site, XirArgument array, XirArgument index, XirArgument length, CiKind elementKind, RiType elementType) { |
252 return new XirSnippet(emptyTemplates[elementKind.ordinal()]); | 278 return new XirSnippet(emptyTemplates[elementKind.ordinal()]); |
309 return new XirSnippet(pair.unresolved, staticTuple, value); | 335 return new XirSnippet(pair.unresolved, staticTuple, value); |
310 } | 336 } |
311 | 337 |
312 @Override | 338 @Override |
313 public XirSnippet genInstanceOf(XirSite site, XirArgument receiver, XirArgument hub, RiType type) { | 339 public XirSnippet genInstanceOf(XirSite site, XirArgument receiver, XirArgument hub, RiType type) { |
314 /* | |
315 if (type.isResolved()) { | 340 if (type.isResolved()) { |
316 return new XirSnippet(instanceofTemplate.resolved, receiver, hub); | 341 return new XirSnippet(instanceofTemplate.resolved, receiver, hub); |
317 } | 342 } |
318 // XirArgument guard = guardFor(type, ResolveClass.SNIPPET); | 343 // XirArgument guard = guardFor(type, ResolveClass.SNIPPET); |
319 return new XirSnippet(instanceofTemplate.unresolved, receiver); | 344 return new XirSnippet(instanceofTemplate.unresolved, receiver); |
320 */ | |
321 return new XirSnippet(emptyTemplates[CiKind.Boolean.ordinal()]); | |
322 } | 345 } |
323 | 346 |
324 @Override | 347 @Override |
325 public XirSnippet genIntrinsic(XirSite site, XirArgument[] arguments, RiMethod method) { | 348 public XirSnippet genIntrinsic(XirSite site, XirArgument[] arguments, RiMethod method) { |
326 return null; | 349 return null; |
376 System.out.println("genResolveClass " + type + ", " + representation); | 399 System.out.println("genResolveClass " + type + ", " + representation); |
377 XirOperand result = asm.restart(CiKind.Object); | 400 XirOperand result = asm.restart(CiKind.Object); |
378 if (type.isResolved()) { | 401 if (type.isResolved()) { |
379 System.out.println("resolved"); | 402 System.out.println("resolved"); |
380 asm.mov(result, asm.o(type)); | 403 asm.mov(result, asm.o(type)); |
381 return new XirSnippet(asm.finishTemplate(result, "resolve class")); | 404 return new XirSnippet(asm.finishTemplate("resolve class")); |
382 } | 405 } |
383 asm.shouldNotReachHere(); | 406 asm.shouldNotReachHere(); |
384 return new XirSnippet(asm.finishTemplate(result, "resolve class")); | 407 return new XirSnippet(asm.finishTemplate("resolve class")); |
385 | 408 |
386 } | 409 } |
387 | 410 |
388 @Override | 411 @Override |
389 public XirSnippet genSafepoint(XirSite site) { | 412 public XirSnippet genSafepoint(XirSite site) { |
390 return new XirSnippet(emptyTemplates[CiKind.Void.ordinal()]); | 413 return new XirSnippet(emptyTemplates[CiKind.Void.ordinal()]); |
391 } | 414 } |
392 | 415 |
393 @Override | 416 @Override |
394 public XirSnippet genExceptionObject(XirSite site) { | 417 public XirSnippet genExceptionObject(XirSite site) { |
395 return new XirSnippet(emptyTemplates[CiKind.Object.ordinal()]); | 418 return new XirSnippet(exceptionObjectTemplate); |
396 } | 419 } |
397 | 420 |
398 } | 421 } |