author | iveresov |
Wed, 20 Jun 2018 17:30:43 -0700 | |
changeset 50689 | 070b5313b2fe |
parent 49873 | 26ebfe8ce852 |
child 50858 | 2d3e99a72541 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
2 |
* Copyright (c) 2012, 2015, 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.stubs; |
|
24 |
||
25 |
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG; |
|
48505
5db30620a3db
8191362: [Graal] gc/g1/TestShrinkAuxiliaryData tests crash with "assert(check_klass_alignment(result)) failed: address not aligned"
thartmann
parents:
47798
diff
changeset
|
26 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayAllocationSize; |
43972 | 27 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord; |
28 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.getAndClearObjectResult; |
|
29 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeMask; |
|
30 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeShift; |
|
31 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeMask; |
|
32 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeShift; |
|
33 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeMask; |
|
34 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeShift; |
|
46344 | 35 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readLayoutHelper; |
43972 | 36 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord; |
47798 | 37 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useCMSIncrementalMode; |
50689
070b5313b2fe
8205105: VM crashes with "assert(Universe::heap()->is_in_reserved(start + words - 1)) failed: not in heap"
iveresov
parents:
49873
diff
changeset
|
38 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useFastTLABRefill; |
43972 | 39 |
import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH; |
40 |
import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.formatArray; |
|
41 |
import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.refillAllocate; |
|
42 |
import static org.graalvm.compiler.hotspot.stubs.StubUtil.handlePendingException; |
|
43 |
import static org.graalvm.compiler.hotspot.stubs.StubUtil.newDescriptor; |
|
44 |
import static org.graalvm.compiler.hotspot.stubs.StubUtil.printf; |
|
45 |
import static org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject; |
|
46 |
||
47 |
import org.graalvm.compiler.api.replacements.Fold; |
|
48 |
import org.graalvm.compiler.api.replacements.Snippet; |
|
49 |
import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter; |
|
50 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; |
|
51 |
import org.graalvm.compiler.graph.Node.ConstantNodeParameter; |
|
52 |
import org.graalvm.compiler.graph.Node.NodeIntrinsic; |
|
53 |
import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; |
|
54 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
|
55 |
import org.graalvm.compiler.hotspot.nodes.GraalHotSpotVMConfigNode; |
|
56 |
import org.graalvm.compiler.hotspot.nodes.StubForeignCallNode; |
|
57 |
import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp; |
|
58 |
import org.graalvm.compiler.hotspot.replacements.NewObjectSnippets; |
|
59 |
import org.graalvm.compiler.hotspot.word.KlassPointer; |
|
60 |
import org.graalvm.compiler.nodes.ConstantNode; |
|
46344 | 61 |
import org.graalvm.compiler.options.OptionValues; |
43972 | 62 |
import org.graalvm.compiler.word.Word; |
49873 | 63 |
import jdk.internal.vm.compiler.word.WordFactory; |
43972 | 64 |
|
65 |
import jdk.vm.ci.code.Register; |
|
66 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
|
67 |
||
68 |
/** |
|
69 |
* Stub implementing the fast path for TLAB refill during instance class allocation. This stub is |
|
70 |
* called from the {@linkplain NewObjectSnippets inline} allocation code when TLAB allocation fails. |
|
71 |
* If this stub fails to refill the TLAB or allocate the object, it calls out to the HotSpot C++ |
|
72 |
* runtime to complete the allocation. |
|
73 |
*/ |
|
74 |
public class NewArrayStub extends SnippetStub { |
|
75 |
||
46344 | 76 |
public NewArrayStub(OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) { |
77 |
super("newArray", options, providers, linkage); |
|
43972 | 78 |
} |
79 |
||
80 |
@Override |
|
81 |
protected Object[] makeConstArgs() { |
|
82 |
HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) providers.getMetaAccess().lookupJavaType(int[].class); |
|
83 |
int count = method.getSignature().getParameterCount(false); |
|
84 |
Object[] args = new Object[count]; |
|
85 |
assert checkConstArg(3, "intArrayHub"); |
|
86 |
assert checkConstArg(4, "threadRegister"); |
|
46344 | 87 |
assert checkConstArg(5, "options"); |
43972 | 88 |
args[3] = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), intArrayType.klass(), null); |
89 |
args[4] = providers.getRegisters().getThreadRegister(); |
|
46344 | 90 |
args[5] = options; |
43972 | 91 |
return args; |
92 |
} |
|
93 |
||
94 |
@Fold |
|
46344 | 95 |
static boolean logging(OptionValues options) { |
96 |
return StubOptions.TraceNewArrayStub.getValue(options); |
|
43972 | 97 |
} |
98 |
||
99 |
/** |
|
100 |
* Re-attempts allocation after an initial TLAB allocation failed or was skipped (e.g., due to |
|
101 |
* -XX:-UseTLAB). |
|
102 |
* |
|
103 |
* @param hub the hub of the object to be allocated |
|
104 |
* @param length the length of the array |
|
105 |
* @param fillContents Should the array be filled with zeroes? |
|
106 |
* @param intArrayHub the hub for {@code int[].class} |
|
107 |
*/ |
|
108 |
@Snippet |
|
46344 | 109 |
private static Object newArray(KlassPointer hub, int length, boolean fillContents, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister, |
110 |
@ConstantParameter OptionValues options) { |
|
111 |
int layoutHelper = readLayoutHelper(hub); |
|
43972 | 112 |
int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG); |
113 |
int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG); |
|
114 |
int elementKind = (layoutHelper >> layoutHelperElementTypeShift(INJECTED_VMCONFIG)) & layoutHelperElementTypeMask(INJECTED_VMCONFIG); |
|
48505
5db30620a3db
8191362: [Graal] gc/g1/TestShrinkAuxiliaryData tests crash with "assert(check_klass_alignment(result)) failed: address not aligned"
thartmann
parents:
47798
diff
changeset
|
115 |
int sizeInBytes = arrayAllocationSize(length, headerSize, log2ElementSize); |
46344 | 116 |
if (logging(options)) { |
43972 | 117 |
printf("newArray: element kind %d\n", elementKind); |
118 |
printf("newArray: array length %d\n", length); |
|
119 |
printf("newArray: array size %d\n", sizeInBytes); |
|
120 |
printf("newArray: hub=%p\n", hub.asWord().rawValue()); |
|
121 |
} |
|
122 |
||
123 |
// check that array length is small enough for fast path. |
|
124 |
Word thread = registerAsWord(threadRegister); |
|
125 |
boolean inlineContiguousAllocationSupported = GraalHotSpotVMConfigNode.inlineContiguousAllocationSupported(); |
|
50689
070b5313b2fe
8205105: VM crashes with "assert(Universe::heap()->is_in_reserved(start + words - 1)) failed: not in heap"
iveresov
parents:
49873
diff
changeset
|
126 |
if (useFastTLABRefill(INJECTED_VMCONFIG) && inlineContiguousAllocationSupported && !useCMSIncrementalMode(INJECTED_VMCONFIG) && length >= 0 && |
070b5313b2fe
8205105: VM crashes with "assert(Universe::heap()->is_in_reserved(start + words - 1)) failed: not in heap"
iveresov
parents:
49873
diff
changeset
|
127 |
length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) { |
46344 | 128 |
Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options)); |
43972 | 129 |
if (memory.notEqual(0)) { |
46344 | 130 |
if (logging(options)) { |
43972 | 131 |
printf("newArray: allocated new array at %p\n", memory.rawValue()); |
132 |
} |
|
133 |
return verifyObject( |
|
46459 | 134 |
formatArray(hub, sizeInBytes, length, headerSize, memory, WordFactory.unsigned(arrayPrototypeMarkWord(INJECTED_VMCONFIG)), fillContents, false, null)); |
43972 | 135 |
} |
136 |
} |
|
46344 | 137 |
if (logging(options)) { |
43972 | 138 |
printf("newArray: calling new_array_c\n"); |
139 |
} |
|
140 |
||
141 |
newArrayC(NEW_ARRAY_C, thread, hub, length); |
|
142 |
handlePendingException(thread, true); |
|
143 |
return verifyObject(getAndClearObjectResult(thread)); |
|
144 |
} |
|
145 |
||
146 |
public static final ForeignCallDescriptor NEW_ARRAY_C = newDescriptor(NewArrayStub.class, "newArrayC", void.class, Word.class, KlassPointer.class, int.class); |
|
147 |
||
148 |
@NodeIntrinsic(StubForeignCallNode.class) |
|
149 |
public static native void newArrayC(@ConstantNodeParameter ForeignCallDescriptor newArrayC, Word thread, KlassPointer hub, int length); |
|
150 |
} |