# HG changeset patch # User Doug Simon # Date 1382370162 -7200 # Node ID 28f56bf7c06aaf817d6ad275ea122e3ced27932d # Parent 128bf29518a037ad221f894ef8788ed0353a243f added support code for Truffle to inject special tail-call code into the prefix of OptimizedCallTarget.call(PackedFrame, Arguments) diff -r 128bf29518a0 -r 28f56bf7c06a graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Mon Oct 21 17:42:19 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Mon Oct 21 17:42:42 2013 +0200 @@ -39,6 +39,7 @@ import com.oracle.graal.asm.amd64.*; import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.compiler.target.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.hotspot.meta.*; @@ -239,6 +240,19 @@ Label verifiedStub = new Label(); // Emit the prefix + emitCodePrefix(installedCodeOwner, tasm, asm, regConfig, config, verifiedStub); + + // Emit code for the LIR + emitCodeBody(installedCodeOwner, tasm, lirGen); + + // Emit the suffix + emitCodeSuffix(installedCodeOwner, tasm, lirGen, asm, frameMap); + } + + /** + * @param installedCodeOwner see {@link Backend#emitCode} + */ + protected void emitCodePrefix(ResolvedJavaMethod installedCodeOwner, TargetMethodAssembler tasm, AMD64MacroAssembler asm, RegisterConfig regConfig, HotSpotVMConfig config, Label verifiedStub) { HotSpotProviders providers = getProviders(); if (installedCodeOwner != null && !isStatic(installedCodeOwner.getModifiers())) { tasm.recordMark(Marks.MARK_UNVERIFIED_ENTRY); @@ -263,10 +277,20 @@ tasm.recordMark(Marks.MARK_OSR_ENTRY); asm.bind(verifiedStub); tasm.recordMark(Marks.MARK_VERIFIED_ENTRY); + } - // Emit code for the LIR + /** + * @param installedCodeOwner see {@link Backend#emitCode} + */ + protected void emitCodeBody(ResolvedJavaMethod installedCodeOwner, TargetMethodAssembler tasm, LIRGenerator lirGen) { lirGen.lir.emitCode(tasm); + } + /** + * @param installedCodeOwner see {@link Backend#emitCode} + */ + protected void emitCodeSuffix(ResolvedJavaMethod installedCodeOwner, TargetMethodAssembler tasm, LIRGenerator lirGen, AMD64MacroAssembler asm, FrameMap frameMap) { + HotSpotProviders providers = getProviders(); HotSpotFrameContext frameContext = (HotSpotFrameContext) tasm.frameContext; if (frameContext != null && !frameContext.isStub) { HotSpotForeignCallsProvider foreignCalls = providers.getForeignCalls(); diff -r 128bf29518a0 -r 28f56bf7c06a graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64HotSpotTruffleBackend.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64HotSpotTruffleBackend.java Mon Oct 21 17:42:42 2013 +0200 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.hotspot.amd64; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.asm.*; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.amd64.*; +import com.oracle.graal.hotspot.meta.*; +import com.oracle.graal.lir.asm.*; +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.frame.*; + +/** + * Subclass of {@link AMD64HotSpotBackend} that injects special code into + * {@link OptimizedCallTarget#call(PackedFrame, Arguments)} for making a tail-call to the entry + * point of the target callee. + */ +class AMD64HotSpotTruffleBackend extends AMD64HotSpotBackend { + + private ResolvedJavaMethod optimizedCallTargetCall; + + public AMD64HotSpotTruffleBackend(HotSpotGraalRuntime runtime, HotSpotProviders providers) { + super(runtime, providers); + } + + private ResolvedJavaMethod getInstrumentedMethod() throws GraalInternalError { + if (optimizedCallTargetCall == null) { + try { + optimizedCallTargetCall = getProviders().getMetaAccess().lookupJavaMethod(OptimizedCallTarget.class.getDeclaredMethod("call", PackedFrame.class, Arguments.class)); + } catch (NoSuchMethodException | SecurityException e) { + throw new GraalInternalError(e); + } + } + return optimizedCallTargetCall; + } + + @Override + protected void emitCodePrefix(ResolvedJavaMethod installedCodeOwner, TargetMethodAssembler tasm, AMD64MacroAssembler asm, RegisterConfig regConfig, HotSpotVMConfig config, Label verifiedStub) { + super.emitCodePrefix(installedCodeOwner, tasm, asm, regConfig, config, verifiedStub); + if (getInstrumentedMethod().equals(installedCodeOwner)) { + // TODO emit tailcall code + } + } +} diff -r 128bf29518a0 -r 28f56bf7c06a graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64HotSpotTruffleBackendFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64HotSpotTruffleBackendFactory.java Mon Oct 21 17:42:42 2013 +0200 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.hotspot.amd64; + +import com.oracle.graal.api.runtime.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.amd64.*; +import com.oracle.graal.hotspot.meta.*; + +/** + * Factory to create a Truffle-specialized AMD64 HotSpot backend. + */ +@ServiceProvider(HotSpotBackendFactory.class) +public class AMD64HotSpotTruffleBackendFactory extends AMD64HotSpotBackendFactory { + + @Override + protected AMD64HotSpotBackend createBackend(HotSpotGraalRuntime runtime, HotSpotProviders providers) { + return new AMD64HotSpotTruffleBackend(runtime, providers); + } +} diff -r 128bf29518a0 -r 28f56bf7c06a mx/projects --- a/mx/projects Mon Oct 21 17:42:19 2013 +0200 +++ b/mx/projects Mon Oct 21 17:42:42 2013 +0200 @@ -32,6 +32,7 @@ com.oracle.graal.hotspot.amd64,\ com.oracle.graal.hotspot.ptx,\ com.oracle.graal.truffle,\ +com.oracle.graal.truffle.hotspot.amd64,\ com.oracle.graal.hotspot.sparc,\ com.oracle.graal.hotspot,\ com.oracle.graal.hotspot.hsail @@ -649,4 +650,11 @@ project@com.oracle.graal.truffle.test@javaCompliance=1.7 project@com.oracle.graal.truffle.test@workingSets=Graal,Truffle,Test - +# graal.truffle.hotspot.amd64 +project@com.oracle.graal.truffle.hotspot.amd64@subDir=graal +project@com.oracle.graal.truffle.hotspot.amd64@sourceDirs=src +project@com.oracle.graal.truffle.hotspot.amd64@dependencies=com.oracle.graal.truffle,com.oracle.graal.hotspot.amd64 +project@com.oracle.graal.truffle.hotspot.amd64@checkstyle=com.oracle.graal.graph +project@com.oracle.graal.truffle.hotspot.amd64@javaCompliance=1.7 +project@com.oracle.graal.truffle.hotspot.amd64@annotationProcessors=com.oracle.graal.service.processor +project@com.oracle.graal.truffle.hotspot.amd64@workingSets=Graal,Truffle