1 /* 2 * Copyright (c) 2011, 2016, 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 package org.graalvm.compiler.hotspot.sparc; 24 25 import static jdk.vm.ci.code.ValueUtil.asRegister; 26 import static jdk.vm.ci.sparc.SPARC.g0; 27 28 import org.graalvm.compiler.asm.sparc.SPARCAddress; 29 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler; 30 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 31 import org.graalvm.compiler.lir.LIRFrameState; 32 import org.graalvm.compiler.lir.LIRInstructionClass; 33 import org.graalvm.compiler.lir.Opcode; 34 import org.graalvm.compiler.lir.asm.CompilationResultBuilder; 35 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 36 import org.graalvm.compiler.lir.sparc.SPARCLIRInstruction; 37 38 import jdk.vm.ci.code.Register; 39 import jdk.vm.ci.code.ValueUtil; 40 import jdk.vm.ci.code.site.InfopointReason; 41 import jdk.vm.ci.meta.AllocatableValue; 42 43 /** 44 * Emits a safepoint poll. 45 */ 46 @Opcode("SAFEPOINT") 47 public class SPARCHotSpotSafepointOp extends SPARCLIRInstruction { 48 public static final LIRInstructionClass<SPARCHotSpotSafepointOp> TYPE = LIRInstructionClass.create(SPARCHotSpotSafepointOp.class); 49 public static final SizeEstimate SIZE = SizeEstimate.create(9); 50 51 @State protected LIRFrameState state; 52 @Use({OperandFlag.REG}) AllocatableValue safepointPollAddress; 53 private final GraalHotSpotVMConfig config; 54 55 public SPARCHotSpotSafepointOp(LIRFrameState state, GraalHotSpotVMConfig config, LIRGeneratorTool tool) { 56 super(TYPE, SIZE); 57 this.state = state; 58 this.config = config; 59 SPARCHotSpotLIRGenerator lirGen = (SPARCHotSpotLIRGenerator) tool; 60 safepointPollAddress = lirGen.getSafepointAddressValue(); 61 } 62 63 @Override 64 public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 65 emitCode(crb, masm, config, false, state, asRegister(safepointPollAddress)); 66 } 67 68 public static void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm, GraalHotSpotVMConfig config, boolean atReturn, LIRFrameState state, Register safepointPollAddress) { 69 crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_FAR : config.MARKID_POLL_FAR); 70 if (state != null) { 71 final int pos = masm.position(); 72 crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); 73 } 74 masm.ldx(new SPARCAddress(safepointPollAddress, 0), g0); 75 } 76 77 public static class SPARCLoadSafepointPollAddress extends SPARCLIRInstruction { 78 public static final LIRInstructionClass<SPARCLoadSafepointPollAddress> TYPE = LIRInstructionClass.create(SPARCLoadSafepointPollAddress.class); 79 public static final SizeEstimate SIZE = SizeEstimate.create(2); 80 81 @Def({OperandFlag.REG}) protected AllocatableValue result; 82 private final GraalHotSpotVMConfig config; 83 84 public SPARCLoadSafepointPollAddress(AllocatableValue result, GraalHotSpotVMConfig config) { 85 super(TYPE, SIZE); 86 this.result = result; 87 this.config = config; 88 } 89 90 @Override 91 public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 92 masm.setx(config.safepointPollingAddress, ValueUtil.asRegister(result), false); 93 } 94 } 95 }