author | dlong |
Thu, 14 Nov 2019 12:21:00 -0800 | |
changeset 59095 | 03fbcd06b4c0 |
parent 52910 | 583fd71c47d6 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
52910 | 2 |
* Copyright (c) 2011, 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 |
||
46344 | 27 |
import static org.graalvm.compiler.core.common.NumUtil.isInt; |
43972 | 28 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
29 |
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode; |
|
30 |
import static jdk.vm.ci.amd64.AMD64.rax; |
|
31 |
import static jdk.vm.ci.amd64.AMD64.rip; |
|
32 |
||
33 |
import org.graalvm.compiler.asm.amd64.AMD64Address; |
|
34 |
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler; |
|
35 |
import org.graalvm.compiler.core.common.LIRKind; |
|
36 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
|
37 |
import org.graalvm.compiler.lir.LIRFrameState; |
|
38 |
import org.graalvm.compiler.lir.LIRInstructionClass; |
|
39 |
import org.graalvm.compiler.lir.Opcode; |
|
40 |
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction; |
|
41 |
import org.graalvm.compiler.lir.asm.CompilationResultBuilder; |
|
42 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; |
|
43 |
||
44 |
import jdk.vm.ci.code.Register; |
|
45 |
import jdk.vm.ci.code.RegisterValue; |
|
46 |
import jdk.vm.ci.code.site.InfopointReason; |
|
47 |
import jdk.vm.ci.meta.AllocatableValue; |
|
48 |
import jdk.vm.ci.meta.JavaConstant; |
|
49 |
import jdk.vm.ci.meta.JavaKind; |
|
50 |
import jdk.vm.ci.meta.Value; |
|
51 |
||
52 |
/** |
|
53 |
* Emits a safepoint poll. |
|
54 |
*/ |
|
55 |
@Opcode("SAFEPOINT") |
|
56 |
public final class AMD64HotSpotSafepointOp extends AMD64LIRInstruction { |
|
57 |
public static final LIRInstructionClass<AMD64HotSpotSafepointOp> TYPE = LIRInstructionClass.create(AMD64HotSpotSafepointOp.class); |
|
58 |
||
59 |
@State protected LIRFrameState state; |
|
60 |
@Temp({OperandFlag.REG, OperandFlag.ILLEGAL}) private AllocatableValue temp; |
|
61 |
||
62 |
private final GraalHotSpotVMConfig config; |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
63 |
private final Register thread; |
43972 | 64 |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
65 |
public AMD64HotSpotSafepointOp(LIRFrameState state, GraalHotSpotVMConfig config, NodeLIRBuilderTool tool, Register thread) { |
43972 | 66 |
super(TYPE); |
67 |
this.state = state; |
|
68 |
this.config = config; |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
69 |
this.thread = thread; |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
70 |
if (config.threadLocalHandshakes || isPollingPageFar(config) || ImmutableCode.getValue(tool.getOptions())) { |
43972 | 71 |
temp = tool.getLIRGeneratorTool().newVariable(LIRKind.value(tool.getLIRGeneratorTool().target().arch.getWordKind())); |
72 |
} else { |
|
73 |
// Don't waste a register if it's unneeded |
|
74 |
temp = Value.ILLEGAL; |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
@Override |
|
79 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler asm) { |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
80 |
emitCode(crb, asm, config, false, state, thread, temp instanceof RegisterValue ? ((RegisterValue) temp).getRegister() : null); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
81 |
} |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
82 |
|
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
83 |
public static void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler asm, GraalHotSpotVMConfig config, boolean atReturn, LIRFrameState state, Register thread, Register scratch) { |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
84 |
if (config.threadLocalHandshakes) { |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
85 |
emitThreadLocalPoll(crb, asm, config, atReturn, state, thread, scratch); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
86 |
} else { |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
87 |
emitGlobalPoll(crb, asm, config, atReturn, state, scratch); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
88 |
} |
43972 | 89 |
} |
90 |
||
91 |
/** |
|
92 |
* Tests if the polling page address can be reached from the code cache with 32-bit |
|
93 |
* displacements. |
|
94 |
*/ |
|
95 |
private static boolean isPollingPageFar(GraalHotSpotVMConfig config) { |
|
96 |
final long pollingPageAddress = config.safepointPollingAddress; |
|
97 |
return config.forceUnreachable || !isInt(pollingPageAddress - config.codeCacheLowBound) || !isInt(pollingPageAddress - config.codeCacheHighBound); |
|
98 |
} |
|
99 |
||
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
100 |
private static void emitGlobalPoll(CompilationResultBuilder crb, AMD64MacroAssembler asm, GraalHotSpotVMConfig config, boolean atReturn, LIRFrameState state, Register scratch) { |
43972 | 101 |
assert !atReturn || state == null : "state is unneeded at return"; |
46344 | 102 |
if (ImmutableCode.getValue(crb.getOptions())) { |
43972 | 103 |
JavaKind hostWordKind = JavaKind.Long; |
104 |
int alignment = hostWordKind.getBitCount() / Byte.SIZE; |
|
105 |
JavaConstant pollingPageAddress = JavaConstant.forIntegerKind(hostWordKind, config.safepointPollingAddress); |
|
106 |
// This move will be patched to load the safepoint page from a data segment |
|
107 |
// co-located with the immutable code. |
|
46344 | 108 |
if (GeneratePIC.getValue(crb.getOptions())) { |
43972 | 109 |
asm.movq(scratch, asm.getPlaceholder(-1)); |
110 |
} else { |
|
111 |
asm.movq(scratch, (AMD64Address) crb.recordDataReferenceInCode(pollingPageAddress, alignment)); |
|
112 |
} |
|
113 |
final int pos = asm.position(); |
|
114 |
crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_FAR : config.MARKID_POLL_FAR); |
|
115 |
if (state != null) { |
|
116 |
crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); |
|
117 |
} |
|
118 |
asm.testl(rax, new AMD64Address(scratch)); |
|
119 |
} else if (isPollingPageFar(config)) { |
|
120 |
asm.movq(scratch, config.safepointPollingAddress); |
|
121 |
crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_FAR : config.MARKID_POLL_FAR); |
|
122 |
final int pos = asm.position(); |
|
123 |
if (state != null) { |
|
124 |
crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); |
|
125 |
} |
|
126 |
asm.testl(rax, new AMD64Address(scratch)); |
|
127 |
} else { |
|
128 |
crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_NEAR : config.MARKID_POLL_NEAR); |
|
129 |
final int pos = asm.position(); |
|
130 |
if (state != null) { |
|
131 |
crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); |
|
132 |
} |
|
133 |
// The C++ code transforms the polling page offset into an RIP displacement |
|
134 |
// to the real address at that offset in the polling page. |
|
135 |
asm.testl(rax, new AMD64Address(rip, 0)); |
|
136 |
} |
|
137 |
} |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
138 |
|
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
139 |
private static void emitThreadLocalPoll(CompilationResultBuilder crb, AMD64MacroAssembler asm, GraalHotSpotVMConfig config, boolean atReturn, LIRFrameState state, Register thread, |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
140 |
Register scratch) { |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
141 |
assert !atReturn || state == null : "state is unneeded at return"; |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
142 |
|
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
143 |
assert config.threadPollingPageOffset >= 0; |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
144 |
asm.movptr(scratch, new AMD64Address(thread, config.threadPollingPageOffset)); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
145 |
crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_FAR : config.MARKID_POLL_FAR); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
146 |
final int pos = asm.position(); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
147 |
if (state != null) { |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
148 |
crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
149 |
} |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
150 |
asm.testl(rax, new AMD64Address(scratch)); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
151 |
} |
43972 | 152 |
} |