43972
|
1 |
/*
|
52910
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.hotspot.amd64;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
|
|
28 |
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.HINT;
|
|
29 |
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
|
|
30 |
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
|
|
31 |
import static jdk.vm.ci.code.ValueUtil.asRegister;
|
|
32 |
import static jdk.vm.ci.code.ValueUtil.isRegister;
|
|
33 |
import static jdk.vm.ci.code.ValueUtil.isStackSlot;
|
|
34 |
|
|
35 |
import org.graalvm.compiler.asm.amd64.AMD64Address;
|
46344
|
36 |
import org.graalvm.compiler.core.common.CompressEncoding;
|
43972
|
37 |
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
|
|
38 |
import org.graalvm.compiler.debug.GraalError;
|
|
39 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
|
40 |
import org.graalvm.compiler.lir.LIRInstructionClass;
|
|
41 |
import org.graalvm.compiler.lir.StandardOp.LoadConstantOp;
|
|
42 |
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
|
|
43 |
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
|
44 |
|
|
45 |
import jdk.vm.ci.code.Register;
|
|
46 |
import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant;
|
|
47 |
import jdk.vm.ci.hotspot.HotSpotObjectConstant;
|
|
48 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
49 |
import jdk.vm.ci.meta.Constant;
|
|
50 |
|
|
51 |
public class AMD64HotSpotMove {
|
|
52 |
|
|
53 |
public static final class HotSpotLoadObjectConstantOp extends AMD64LIRInstruction implements LoadConstantOp {
|
|
54 |
public static final LIRInstructionClass<HotSpotLoadObjectConstantOp> TYPE = LIRInstructionClass.create(HotSpotLoadObjectConstantOp.class);
|
|
55 |
|
|
56 |
@Def({REG, STACK}) private AllocatableValue result;
|
|
57 |
private final HotSpotObjectConstant input;
|
|
58 |
|
|
59 |
public HotSpotLoadObjectConstantOp(AllocatableValue result, HotSpotObjectConstant input) {
|
|
60 |
super(TYPE);
|
|
61 |
this.result = result;
|
|
62 |
this.input = input;
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
46344
|
67 |
if (GeneratePIC.getValue(crb.getOptions())) {
|
43972
|
68 |
throw GraalError.shouldNotReachHere("Object constant load should not be happening directly");
|
|
69 |
}
|
|
70 |
boolean compressed = input.isCompressed();
|
|
71 |
if (crb.target.inlineObjects) {
|
|
72 |
crb.recordInlineDataInCode(input);
|
|
73 |
if (isRegister(result)) {
|
|
74 |
if (compressed) {
|
|
75 |
masm.movl(asRegister(result), 0xDEADDEAD);
|
|
76 |
} else {
|
|
77 |
masm.movq(asRegister(result), 0xDEADDEADDEADDEADL);
|
|
78 |
}
|
|
79 |
} else {
|
|
80 |
assert isStackSlot(result);
|
|
81 |
if (compressed) {
|
|
82 |
masm.movl((AMD64Address) crb.asAddress(result), 0xDEADDEAD);
|
|
83 |
} else {
|
|
84 |
throw GraalError.shouldNotReachHere("Cannot store 64-bit constants to memory");
|
|
85 |
}
|
|
86 |
}
|
|
87 |
} else {
|
|
88 |
if (isRegister(result)) {
|
|
89 |
AMD64Address address = (AMD64Address) crb.recordDataReferenceInCode(input, compressed ? 4 : 8);
|
|
90 |
if (compressed) {
|
|
91 |
masm.movl(asRegister(result), address);
|
|
92 |
} else {
|
|
93 |
masm.movq(asRegister(result), address);
|
|
94 |
}
|
|
95 |
} else {
|
|
96 |
throw GraalError.shouldNotReachHere("Cannot directly store data patch to memory");
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
@Override
|
|
102 |
public Constant getConstant() {
|
|
103 |
return input;
|
|
104 |
}
|
|
105 |
|
|
106 |
@Override
|
|
107 |
public AllocatableValue getResult() {
|
|
108 |
return result;
|
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
public static final class BaseMove extends AMD64LIRInstruction {
|
|
113 |
public static final LIRInstructionClass<BaseMove> TYPE = LIRInstructionClass.create(BaseMove.class);
|
|
114 |
|
|
115 |
@Def({REG, HINT}) protected AllocatableValue result;
|
|
116 |
private final GraalHotSpotVMConfig config;
|
|
117 |
|
|
118 |
public BaseMove(AllocatableValue result, GraalHotSpotVMConfig config) {
|
|
119 |
super(TYPE);
|
|
120 |
this.result = result;
|
|
121 |
this.config = config;
|
|
122 |
}
|
|
123 |
|
|
124 |
@Override
|
|
125 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
|
126 |
masm.movq(asRegister(result), masm.getPlaceholder(-1));
|
|
127 |
crb.recordMark(config.MARKID_NARROW_KLASS_BASE_ADDRESS);
|
|
128 |
}
|
|
129 |
|
|
130 |
}
|
|
131 |
|
|
132 |
public static final class HotSpotLoadMetaspaceConstantOp extends AMD64LIRInstruction implements LoadConstantOp {
|
|
133 |
public static final LIRInstructionClass<HotSpotLoadMetaspaceConstantOp> TYPE = LIRInstructionClass.create(HotSpotLoadMetaspaceConstantOp.class);
|
|
134 |
|
|
135 |
@Def({REG, STACK}) private AllocatableValue result;
|
|
136 |
private final HotSpotMetaspaceConstant input;
|
|
137 |
|
|
138 |
public HotSpotLoadMetaspaceConstantOp(AllocatableValue result, HotSpotMetaspaceConstant input) {
|
|
139 |
super(TYPE);
|
|
140 |
this.result = result;
|
|
141 |
this.input = input;
|
|
142 |
}
|
|
143 |
|
|
144 |
@Override
|
|
145 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
46344
|
146 |
if (GeneratePIC.getValue(crb.getOptions())) {
|
43972
|
147 |
throw GraalError.shouldNotReachHere("Metaspace constant load should not be happening directly");
|
|
148 |
}
|
|
149 |
boolean compressed = input.isCompressed();
|
|
150 |
if (isRegister(result)) {
|
|
151 |
if (compressed) {
|
|
152 |
crb.recordInlineDataInCode(input);
|
|
153 |
masm.movl(asRegister(result), 0xDEADDEAD);
|
|
154 |
} else {
|
|
155 |
crb.recordInlineDataInCode(input);
|
|
156 |
masm.movq(asRegister(result), 0xDEADDEADDEADDEADL);
|
|
157 |
}
|
|
158 |
} else {
|
|
159 |
assert isStackSlot(result);
|
|
160 |
if (compressed) {
|
|
161 |
crb.recordInlineDataInCode(input);
|
|
162 |
masm.movl((AMD64Address) crb.asAddress(result), 0xDEADDEAD);
|
|
163 |
} else {
|
|
164 |
throw GraalError.shouldNotReachHere("Cannot store 64-bit constants to memory");
|
|
165 |
}
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
@Override
|
|
170 |
public Constant getConstant() {
|
|
171 |
return input;
|
|
172 |
}
|
|
173 |
|
|
174 |
@Override
|
|
175 |
public AllocatableValue getResult() {
|
|
176 |
return result;
|
|
177 |
}
|
|
178 |
}
|
|
179 |
|
|
180 |
public static void decodeKlassPointer(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register register, Register scratch, AMD64Address address, GraalHotSpotVMConfig config) {
|
|
181 |
CompressEncoding encoding = config.getKlassEncoding();
|
|
182 |
masm.movl(register, address);
|
46344
|
183 |
if (encoding.getShift() != 0) {
|
|
184 |
masm.shlq(register, encoding.getShift());
|
43972
|
185 |
}
|
46344
|
186 |
boolean pic = GeneratePIC.getValue(crb.getOptions());
|
|
187 |
if (pic || encoding.hasBase()) {
|
|
188 |
if (pic) {
|
43972
|
189 |
masm.movq(scratch, masm.getPlaceholder(-1));
|
|
190 |
crb.recordMark(config.MARKID_NARROW_KLASS_BASE_ADDRESS);
|
|
191 |
} else {
|
46344
|
192 |
assert encoding.getBase() != 0;
|
|
193 |
masm.movq(scratch, encoding.getBase());
|
43972
|
194 |
}
|
|
195 |
masm.addq(register, scratch);
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|