author | dlong |
Tue, 24 Sep 2019 12:47:15 -0400 | |
changeset 58299 | 6df94ce3ab2f |
parent 52956 | 4b0b796dd581 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
58299 | 2 |
* Copyright (c) 2013, 2019, 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; |
26 |
||
46393 | 27 |
import static jdk.vm.ci.code.CodeUtil.K; |
43972 | 28 |
import static jdk.vm.ci.code.CodeUtil.getCallingConvention; |
29 |
import static jdk.vm.ci.common.InitTimer.timer; |
|
30 |
||
46640 | 31 |
import java.util.Collections; |
32 |
||
58299 | 33 |
import org.graalvm.compiler.core.common.CompilationIdentifier; |
46393 | 34 |
import org.graalvm.compiler.core.common.NumUtil; |
58299 | 35 |
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig; |
43972 | 36 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; |
58299 | 37 |
import org.graalvm.compiler.core.gen.LIRGenerationProvider; |
46640 | 38 |
import org.graalvm.compiler.debug.DebugHandlersFactory; |
43972 | 39 |
import org.graalvm.compiler.hotspot.meta.HotSpotHostForeignCallsProvider; |
40 |
import org.graalvm.compiler.hotspot.meta.HotSpotLoweringProvider; |
|
41 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
|
42 |
import org.graalvm.compiler.hotspot.stubs.Stub; |
|
58299 | 43 |
import org.graalvm.compiler.lir.LIR; |
43972 | 44 |
import org.graalvm.compiler.lir.asm.CompilationResultBuilder; |
58299 | 45 |
import org.graalvm.compiler.lir.framemap.FrameMapBuilder; |
43972 | 46 |
import org.graalvm.compiler.lir.framemap.ReferenceMapBuilder; |
58299 | 47 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult; |
43972 | 48 |
import org.graalvm.compiler.nodes.StructuredGraph; |
46344 | 49 |
import org.graalvm.compiler.options.OptionValues; |
46640 | 50 |
import org.graalvm.compiler.printer.GraalDebugHandlersFactory; |
52578 | 51 |
import org.graalvm.compiler.word.Word; |
43972 | 52 |
|
53 |
import jdk.vm.ci.code.CallingConvention; |
|
58299 | 54 |
import jdk.vm.ci.code.RegisterConfig; |
43972 | 55 |
import jdk.vm.ci.common.InitTimer; |
56 |
import jdk.vm.ci.hotspot.HotSpotCallingConventionType; |
|
57 |
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; |
|
48398 | 58 |
import jdk.vm.ci.meta.JavaKind; |
43972 | 59 |
import jdk.vm.ci.meta.JavaType; |
60 |
import jdk.vm.ci.runtime.JVMCICompiler; |
|
61 |
||
62 |
/** |
|
63 |
* Common functionality of HotSpot host backends. |
|
64 |
*/ |
|
58299 | 65 |
public abstract class HotSpotHostBackend extends HotSpotBackend implements LIRGenerationProvider { |
43972 | 66 |
|
67 |
/** |
|
46344 | 68 |
* Descriptor for {@code SharedRuntime::deopt_blob()->unpack()}. |
43972 | 69 |
*/ |
70 |
public static final ForeignCallDescriptor DEOPTIMIZATION_HANDLER = new ForeignCallDescriptor("deoptHandler", void.class); |
|
71 |
||
72 |
/** |
|
46344 | 73 |
* Descriptor for {@code SharedRuntime::deopt_blob()->uncommon_trap()}. |
43972 | 74 |
*/ |
75 |
public static final ForeignCallDescriptor UNCOMMON_TRAP_HANDLER = new ForeignCallDescriptor("uncommonTrapHandler", void.class); |
|
76 |
||
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
77 |
public static final ForeignCallDescriptor ENABLE_STACK_RESERVED_ZONE = new ForeignCallDescriptor("enableStackReservedZoneEntry", void.class, Word.class); |
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
78 |
|
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
79 |
public static final ForeignCallDescriptor THROW_DELAYED_STACKOVERFLOW_ERROR = new ForeignCallDescriptor("throwDelayedStackoverflowError", void.class); |
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
80 |
|
43972 | 81 |
protected final GraalHotSpotVMConfig config; |
82 |
||
83 |
public HotSpotHostBackend(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) { |
|
84 |
super(runtime, providers); |
|
85 |
this.config = config; |
|
86 |
} |
|
87 |
||
88 |
@Override |
|
89 |
@SuppressWarnings("try") |
|
46344 | 90 |
public void completeInitialization(HotSpotJVMCIRuntime jvmciRuntime, OptionValues options) { |
43972 | 91 |
final HotSpotProviders providers = getProviders(); |
92 |
HotSpotHostForeignCallsProvider foreignCalls = (HotSpotHostForeignCallsProvider) providers.getForeignCalls(); |
|
93 |
final HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer(); |
|
94 |
||
95 |
try (InitTimer st = timer("foreignCalls.initialize")) { |
|
46344 | 96 |
foreignCalls.initialize(providers, options); |
43972 | 97 |
} |
98 |
try (InitTimer st = timer("lowerer.initialize")) { |
|
46640 | 99 |
Iterable<DebugHandlersFactory> factories = Collections.singletonList(new GraalDebugHandlersFactory(providers.getSnippetReflection())); |
100 |
lowerer.initialize(options, factories, providers, config); |
|
43972 | 101 |
} |
52956 | 102 |
providers.getReplacements().closeSnippetRegistration(); |
43972 | 103 |
} |
104 |
||
105 |
protected CallingConvention makeCallingConvention(StructuredGraph graph, Stub stub) { |
|
106 |
if (stub != null) { |
|
107 |
return stub.getLinkage().getIncomingCallingConvention(); |
|
108 |
} |
|
109 |
||
110 |
CallingConvention cc = getCallingConvention(getCodeCache(), HotSpotCallingConventionType.JavaCallee, graph.method(), this); |
|
111 |
if (graph.getEntryBCI() != JVMCICompiler.INVOCATION_ENTRY_BCI) { |
|
112 |
// for OSR, only a pointer is passed to the method. |
|
113 |
JavaType[] parameterTypes = new JavaType[]{getMetaAccess().lookupJavaType(long.class)}; |
|
114 |
CallingConvention tmp = getCodeCache().getRegisterConfig().getCallingConvention(HotSpotCallingConventionType.JavaCallee, getMetaAccess().lookupJavaType(void.class), parameterTypes, this); |
|
115 |
cc = new CallingConvention(cc.getStackSize(), cc.getReturn(), tmp.getArgument(0)); |
|
116 |
} |
|
117 |
return cc; |
|
118 |
} |
|
119 |
||
120 |
public void emitStackOverflowCheck(CompilationResultBuilder crb) { |
|
121 |
if (config.useStackBanging) { |
|
122 |
// Each code entry causes one stack bang n pages down the stack where n |
|
123 |
// is configurable by StackShadowPages. The setting depends on the maximum |
|
124 |
// depth of VM call stack or native before going back into java code, |
|
125 |
// since only java code can raise a stack overflow exception using the |
|
126 |
// stack banging mechanism. The VM and native code does not detect stack |
|
127 |
// overflow. |
|
128 |
// The code in JavaCalls::call() checks that there is at least n pages |
|
129 |
// available, so all entry code needs to do is bang once for the end of |
|
130 |
// this shadow zone. |
|
131 |
// The entry code may need to bang additional pages if the framesize |
|
132 |
// is greater than a page. |
|
133 |
||
134 |
int pageSize = config.vmPageSize; |
|
46393 | 135 |
int bangEnd = NumUtil.roundUp(config.stackShadowPages * 4 * K, pageSize); |
43972 | 136 |
|
137 |
// This is how far the previous frame's stack banging extended. |
|
138 |
int bangEndSafe = bangEnd; |
|
139 |
||
140 |
int frameSize = Math.max(crb.frameMap.frameSize(), crb.compilationResult.getMaxInterpreterFrameSize()); |
|
141 |
if (frameSize > pageSize) { |
|
142 |
bangEnd += frameSize; |
|
143 |
} |
|
144 |
||
145 |
int bangOffset = bangEndSafe; |
|
146 |
if (bangOffset <= bangEnd) { |
|
147 |
crb.blockComment("[stack overflow check]"); |
|
148 |
} |
|
149 |
while (bangOffset <= bangEnd) { |
|
150 |
// Need at least one stack bang at end of shadow zone. |
|
151 |
bangStackWithOffset(crb, bangOffset); |
|
152 |
bangOffset += pageSize; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
protected abstract void bangStackWithOffset(CompilationResultBuilder crb, int bangOffset); |
|
158 |
||
159 |
@Override |
|
160 |
public ReferenceMapBuilder newReferenceMapBuilder(int totalFrameSize) { |
|
48398 | 161 |
int uncompressedReferenceSize = getTarget().arch.getPlatformKind(JavaKind.Object).getSizeInBytes(); |
162 |
return new HotSpotReferenceMapBuilder(totalFrameSize, config.maxOopMapStackOffset, uncompressedReferenceSize); |
|
43972 | 163 |
} |
164 |
||
58299 | 165 |
@Override |
166 |
public LIRGenerationResult newLIRGenerationResult(CompilationIdentifier compilationId, LIR lir, RegisterAllocationConfig registerAllocationConfig, StructuredGraph graph, Object stub) { |
|
167 |
return new HotSpotLIRGenerationResult(compilationId, lir, newFrameMapBuilder(registerAllocationConfig.getRegisterConfig()), registerAllocationConfig, makeCallingConvention(graph, (Stub) stub), |
|
168 |
stub, |
|
169 |
config.requiresReservedStackCheck(graph.getMethods())); |
|
170 |
} |
|
171 |
||
172 |
protected abstract FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig); |
|
43972 | 173 |
} |