< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotBackend.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2012, 2018, 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 
  24 
  25 package org.graalvm.compiler.hotspot.amd64;
  26 
  27 import static jdk.vm.ci.amd64.AMD64.r10;
  28 import static jdk.vm.ci.amd64.AMD64.rax;
  29 import static jdk.vm.ci.amd64.AMD64.rsp;
  30 import static jdk.vm.ci.code.ValueUtil.asRegister;
  31 import static org.graalvm.compiler.core.common.GraalOptions.CanOmitFrame;
  32 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  33 import static org.graalvm.compiler.core.common.GraalOptions.ZapStackOnMethodEntry;
  34 
  35 import jdk.internal.vm.compiler.collections.EconomicSet;
  36 import org.graalvm.compiler.asm.Assembler;
  37 import org.graalvm.compiler.asm.Label;
  38 import org.graalvm.compiler.asm.amd64.AMD64Address;
  39 import org.graalvm.compiler.asm.amd64.AMD64Assembler.ConditionFlag;
  40 import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
  41 import org.graalvm.compiler.code.CompilationResult;
  42 import org.graalvm.compiler.core.amd64.AMD64NodeMatchRules;
  43 import org.graalvm.compiler.core.common.CompilationIdentifier;
  44 import org.graalvm.compiler.core.common.LIRKind;
  45 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
  46 import org.graalvm.compiler.core.gen.LIRGenerationProvider;
  47 import org.graalvm.compiler.debug.DebugContext;
  48 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  49 import org.graalvm.compiler.hotspot.HotSpotDataBuilder;
  50 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  51 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
  52 import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult;
  53 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction;
  54 import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
  55 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  56 import org.graalvm.compiler.hotspot.stubs.Stub;
  57 import org.graalvm.compiler.lir.LIR;
  58 import org.graalvm.compiler.lir.amd64.AMD64Call;
  59 import org.graalvm.compiler.lir.amd64.AMD64FrameMap;
  60 import org.graalvm.compiler.lir.amd64.AMD64FrameMapBuilder;
  61 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  62 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
  63 import org.graalvm.compiler.lir.asm.DataBuilder;


  74 import jdk.vm.ci.amd64.AMD64Kind;
  75 import jdk.vm.ci.code.CallingConvention;
  76 import jdk.vm.ci.code.Register;
  77 import jdk.vm.ci.code.RegisterConfig;
  78 import jdk.vm.ci.code.StackSlot;
  79 import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
  80 import jdk.vm.ci.hotspot.HotSpotSentinelConstant;
  81 import jdk.vm.ci.meta.JavaKind;
  82 import jdk.vm.ci.meta.JavaType;
  83 import jdk.vm.ci.meta.ResolvedJavaMethod;
  84 
  85 /**
  86  * HotSpot AMD64 specific backend.
  87  */
  88 public class AMD64HotSpotBackend extends HotSpotHostBackend implements LIRGenerationProvider {
  89 
  90     public AMD64HotSpotBackend(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) {
  91         super(config, runtime, providers);
  92     }
  93 
  94     private FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig) {

  95         RegisterConfig registerConfigNonNull = registerConfig == null ? getCodeCache().getRegisterConfig() : registerConfig;
  96         FrameMap frameMap = new AMD64FrameMap(getCodeCache(), registerConfigNonNull, this);
  97         return new AMD64FrameMapBuilder(frameMap, getCodeCache(), registerConfigNonNull);
  98     }
  99 
 100     @Override
 101     public LIRGeneratorTool newLIRGenerator(LIRGenerationResult lirGenRes) {
 102         return new AMD64HotSpotLIRGenerator(getProviders(), config, lirGenRes);
 103     }
 104 
 105     @Override
 106     public LIRGenerationResult newLIRGenerationResult(CompilationIdentifier compilationId, LIR lir, RegisterConfig registerConfig, StructuredGraph graph, Object stub) {
 107         return new HotSpotLIRGenerationResult(compilationId, lir, newFrameMapBuilder(registerConfig), makeCallingConvention(graph, (Stub) stub), stub,
 108                         config.requiresReservedStackCheck(graph.getMethods()));
 109     }
 110 
 111     @Override
 112     public NodeLIRBuilderTool newNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) {
 113         return new AMD64HotSpotNodeLIRBuilder(graph, lirGen, new AMD64NodeMatchRules(lirGen));
 114     }
 115 
 116     @Override
 117     protected void bangStackWithOffset(CompilationResultBuilder crb, int bangOffset) {
 118         AMD64MacroAssembler asm = (AMD64MacroAssembler) crb.asm;
 119         int pos = asm.position();
 120         asm.movl(new AMD64Address(rsp, -bangOffset), AMD64.rax);
 121         assert asm.position() - pos >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE;
 122     }
 123 
 124     /**
 125      * The size of the instruction used to patch the verified entry point of an nmethod when the
 126      * nmethod is made non-entrant or a zombie (e.g. during deopt or class unloading). The first
 127      * instruction emitted at an nmethod's verified entry point must be at least this length to
 128      * ensure mt-safe patching.
 129      */
 130     public static final int PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE = 5;
 131 


 202         HotSpotLIRGenerationResult gen = (HotSpotLIRGenerationResult) lirGenRen;
 203         LIR lir = gen.getLIR();
 204         assert gen.getDeoptimizationRescueSlot() == null || frameMap.frameNeedsAllocating() : "method that can deoptimize must have a frame";
 205         OptionValues options = lir.getOptions();
 206         DebugContext debug = lir.getDebug();
 207         boolean omitFrame = CanOmitFrame.getValue(options) && !frameMap.frameNeedsAllocating() && !lir.hasArgInCallerFrame() && !gen.hasForeignCall();
 208 
 209         Stub stub = gen.getStub();
 210         Assembler masm = new AMD64MacroAssembler(getTarget());
 211         HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null, omitFrame);
 212         DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());
 213         CompilationResultBuilder crb = factory.createBuilder(getCodeCache(), getForeignCalls(), frameMap, masm, dataBuilder, frameContext, options, debug, compilationResult, Register.None);
 214         crb.setTotalFrameSize(frameMap.totalFrameSize());
 215         crb.setMaxInterpreterFrameSize(gen.getMaxInterpreterFrameSize());
 216         StackSlot deoptimizationRescueSlot = gen.getDeoptimizationRescueSlot();
 217         if (deoptimizationRescueSlot != null && stub == null) {
 218             crb.compilationResult.setCustomStackAreaOffset(deoptimizationRescueSlot);
 219         }
 220 
 221         if (stub != null) {
 222             EconomicSet<Register> destroyedCallerRegisters = gatherDestroyedCallerRegisters(lir);
 223             updateStub(stub, destroyedCallerRegisters, gen.getCalleeSaveInfo(), frameMap);
 224         }
 225 
 226         return crb;
 227     }
 228 
 229     @Override
 230     public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner) {
 231         AMD64MacroAssembler asm = (AMD64MacroAssembler) crb.asm;
 232         FrameMap frameMap = crb.frameMap;
 233         RegisterConfig regConfig = frameMap.getRegisterConfig();
 234         Label verifiedEntry = new Label();
 235 
 236         // Emit the prefix
 237         emitCodePrefix(installedCodeOwner, crb, asm, regConfig, verifiedEntry);
 238 
 239         // Emit code for the LIR
 240         emitCodeBody(installedCodeOwner, crb, lir);
 241 
 242         // Emit the suffix
 243         emitCodeSuffix(installedCodeOwner, crb, asm, frameMap);


   1 /*
   2  * Copyright (c) 2012, 2019, 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 
  24 
  25 package org.graalvm.compiler.hotspot.amd64;
  26 
  27 import static jdk.vm.ci.amd64.AMD64.r10;
  28 import static jdk.vm.ci.amd64.AMD64.rax;
  29 import static jdk.vm.ci.amd64.AMD64.rsp;
  30 import static jdk.vm.ci.code.ValueUtil.asRegister;
  31 import static org.graalvm.compiler.core.common.GraalOptions.CanOmitFrame;
  32 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  33 import static org.graalvm.compiler.core.common.GraalOptions.ZapStackOnMethodEntry;
  34 
  35 import jdk.internal.vm.compiler.collections.EconomicSet;
  36 import org.graalvm.compiler.asm.Assembler;
  37 import org.graalvm.compiler.asm.Label;
  38 import org.graalvm.compiler.asm.amd64.AMD64Address;
  39 import org.graalvm.compiler.asm.amd64.AMD64Assembler.ConditionFlag;
  40 import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
  41 import org.graalvm.compiler.code.CompilationResult;
  42 import org.graalvm.compiler.core.amd64.AMD64NodeMatchRules;

  43 import org.graalvm.compiler.core.common.LIRKind;
  44 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
  45 import org.graalvm.compiler.core.gen.LIRGenerationProvider;
  46 import org.graalvm.compiler.debug.DebugContext;
  47 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  48 import org.graalvm.compiler.hotspot.HotSpotDataBuilder;
  49 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  50 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
  51 import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult;
  52 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction;
  53 import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
  54 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  55 import org.graalvm.compiler.hotspot.stubs.Stub;
  56 import org.graalvm.compiler.lir.LIR;
  57 import org.graalvm.compiler.lir.amd64.AMD64Call;
  58 import org.graalvm.compiler.lir.amd64.AMD64FrameMap;
  59 import org.graalvm.compiler.lir.amd64.AMD64FrameMapBuilder;
  60 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  61 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
  62 import org.graalvm.compiler.lir.asm.DataBuilder;


  73 import jdk.vm.ci.amd64.AMD64Kind;
  74 import jdk.vm.ci.code.CallingConvention;
  75 import jdk.vm.ci.code.Register;
  76 import jdk.vm.ci.code.RegisterConfig;
  77 import jdk.vm.ci.code.StackSlot;
  78 import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
  79 import jdk.vm.ci.hotspot.HotSpotSentinelConstant;
  80 import jdk.vm.ci.meta.JavaKind;
  81 import jdk.vm.ci.meta.JavaType;
  82 import jdk.vm.ci.meta.ResolvedJavaMethod;
  83 
  84 /**
  85  * HotSpot AMD64 specific backend.
  86  */
  87 public class AMD64HotSpotBackend extends HotSpotHostBackend implements LIRGenerationProvider {
  88 
  89     public AMD64HotSpotBackend(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) {
  90         super(config, runtime, providers);
  91     }
  92 
  93     @Override
  94     protected FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig) {
  95         RegisterConfig registerConfigNonNull = registerConfig == null ? getCodeCache().getRegisterConfig() : registerConfig;
  96         FrameMap frameMap = new AMD64FrameMap(getCodeCache(), registerConfigNonNull, this);
  97         return new AMD64FrameMapBuilder(frameMap, getCodeCache(), registerConfigNonNull);
  98     }
  99 
 100     @Override
 101     public LIRGeneratorTool newLIRGenerator(LIRGenerationResult lirGenRes) {
 102         return new AMD64HotSpotLIRGenerator(getProviders(), config, lirGenRes);
 103     }
 104 
 105     @Override






 106     public NodeLIRBuilderTool newNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) {
 107         return new AMD64HotSpotNodeLIRBuilder(graph, lirGen, new AMD64NodeMatchRules(lirGen));
 108     }
 109 
 110     @Override
 111     protected void bangStackWithOffset(CompilationResultBuilder crb, int bangOffset) {
 112         AMD64MacroAssembler asm = (AMD64MacroAssembler) crb.asm;
 113         int pos = asm.position();
 114         asm.movl(new AMD64Address(rsp, -bangOffset), AMD64.rax);
 115         assert asm.position() - pos >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE;
 116     }
 117 
 118     /**
 119      * The size of the instruction used to patch the verified entry point of an nmethod when the
 120      * nmethod is made non-entrant or a zombie (e.g. during deopt or class unloading). The first
 121      * instruction emitted at an nmethod's verified entry point must be at least this length to
 122      * ensure mt-safe patching.
 123      */
 124     public static final int PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE = 5;
 125 


 196         HotSpotLIRGenerationResult gen = (HotSpotLIRGenerationResult) lirGenRen;
 197         LIR lir = gen.getLIR();
 198         assert gen.getDeoptimizationRescueSlot() == null || frameMap.frameNeedsAllocating() : "method that can deoptimize must have a frame";
 199         OptionValues options = lir.getOptions();
 200         DebugContext debug = lir.getDebug();
 201         boolean omitFrame = CanOmitFrame.getValue(options) && !frameMap.frameNeedsAllocating() && !lir.hasArgInCallerFrame() && !gen.hasForeignCall();
 202 
 203         Stub stub = gen.getStub();
 204         Assembler masm = new AMD64MacroAssembler(getTarget());
 205         HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null, omitFrame);
 206         DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());
 207         CompilationResultBuilder crb = factory.createBuilder(getCodeCache(), getForeignCalls(), frameMap, masm, dataBuilder, frameContext, options, debug, compilationResult, Register.None);
 208         crb.setTotalFrameSize(frameMap.totalFrameSize());
 209         crb.setMaxInterpreterFrameSize(gen.getMaxInterpreterFrameSize());
 210         StackSlot deoptimizationRescueSlot = gen.getDeoptimizationRescueSlot();
 211         if (deoptimizationRescueSlot != null && stub == null) {
 212             crb.compilationResult.setCustomStackAreaOffset(deoptimizationRescueSlot);
 213         }
 214 
 215         if (stub != null) {
 216             updateStub(stub, gen, frameMap);

 217         }
 218 
 219         return crb;
 220     }
 221 
 222     @Override
 223     public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner) {
 224         AMD64MacroAssembler asm = (AMD64MacroAssembler) crb.asm;
 225         FrameMap frameMap = crb.frameMap;
 226         RegisterConfig regConfig = frameMap.getRegisterConfig();
 227         Label verifiedEntry = new Label();
 228 
 229         // Emit the prefix
 230         emitCodePrefix(installedCodeOwner, crb, asm, regConfig, verifiedEntry);
 231 
 232         // Emit code for the LIR
 233         emitCodeBody(installedCodeOwner, crb, lir);
 234 
 235         // Emit the suffix
 236         emitCodeSuffix(installedCodeOwner, crb, asm, frameMap);


< prev index next >