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;
26 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord;
27 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.getAndClearObjectResult;
28 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeMask;
29 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeShift;
30 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeMask;
31 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeShift;
32 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeMask;
33 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeShift;
34 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readLayoutHelper;
35 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord;
36 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.wordSize;
37 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH;
38 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.formatArray;
39 import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.refillAllocate;
40 import static org.graalvm.compiler.hotspot.stubs.StubUtil.handlePendingException;
41 import static org.graalvm.compiler.hotspot.stubs.StubUtil.newDescriptor;
42 import static org.graalvm.compiler.hotspot.stubs.StubUtil.printf;
43 import static org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject;
44 import static jdk.vm.ci.hotspot.HotSpotMetaAccessProvider.computeArrayAllocationSize;
45
46 import org.graalvm.compiler.api.replacements.Fold;
47 import org.graalvm.compiler.api.replacements.Snippet;
48 import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
49 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
50 import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
51 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
52 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
53 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
54 import org.graalvm.compiler.hotspot.nodes.GraalHotSpotVMConfigNode;
55 import org.graalvm.compiler.hotspot.nodes.StubForeignCallNode;
105 * @param intArrayHub the hub for {@code int[].class}
106 */
107 @Snippet
108 private static Object newArray(KlassPointer hub, int length, boolean fillContents, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister,
109 @ConstantParameter OptionValues options) {
110 int layoutHelper = readLayoutHelper(hub);
111 int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG);
112 int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG);
113 int elementKind = (layoutHelper >> layoutHelperElementTypeShift(INJECTED_VMCONFIG)) & layoutHelperElementTypeMask(INJECTED_VMCONFIG);
114 int sizeInBytes = computeArrayAllocationSize(length, wordSize(), headerSize, log2ElementSize);
115 if (logging(options)) {
116 printf("newArray: element kind %d\n", elementKind);
117 printf("newArray: array length %d\n", length);
118 printf("newArray: array size %d\n", sizeInBytes);
119 printf("newArray: hub=%p\n", hub.asWord().rawValue());
120 }
121
122 // check that array length is small enough for fast path.
123 Word thread = registerAsWord(threadRegister);
124 boolean inlineContiguousAllocationSupported = GraalHotSpotVMConfigNode.inlineContiguousAllocationSupported();
125 if (inlineContiguousAllocationSupported && length >= 0 && length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) {
126 Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options));
127 if (memory.notEqual(0)) {
128 if (logging(options)) {
129 printf("newArray: allocated new array at %p\n", memory.rawValue());
130 }
131 return verifyObject(
132 formatArray(hub, sizeInBytes, length, headerSize, memory, WordFactory.unsigned(arrayPrototypeMarkWord(INJECTED_VMCONFIG)), fillContents, false, null));
133 }
134 }
135 if (logging(options)) {
136 printf("newArray: calling new_array_c\n");
137 }
138
139 newArrayC(NEW_ARRAY_C, thread, hub, length);
140 handlePendingException(thread, true);
141 return verifyObject(getAndClearObjectResult(thread));
142 }
143
144 public static final ForeignCallDescriptor NEW_ARRAY_C = newDescriptor(NewArrayStub.class, "newArrayC", void.class, Word.class, KlassPointer.class, int.class);
145
|
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;
26 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord;
27 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.getAndClearObjectResult;
28 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeMask;
29 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeShift;
30 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeMask;
31 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeShift;
32 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeMask;
33 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeShift;
34 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readLayoutHelper;
35 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord;
36 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useCMSIncrementalMode;
37 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.wordSize;
38 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH;
39 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.formatArray;
40 import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.refillAllocate;
41 import static org.graalvm.compiler.hotspot.stubs.StubUtil.handlePendingException;
42 import static org.graalvm.compiler.hotspot.stubs.StubUtil.newDescriptor;
43 import static org.graalvm.compiler.hotspot.stubs.StubUtil.printf;
44 import static org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject;
45 import static jdk.vm.ci.hotspot.HotSpotMetaAccessProvider.computeArrayAllocationSize;
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;
106 * @param intArrayHub the hub for {@code int[].class}
107 */
108 @Snippet
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);
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);
115 int sizeInBytes = computeArrayAllocationSize(length, wordSize(), headerSize, log2ElementSize);
116 if (logging(options)) {
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();
126 if (inlineContiguousAllocationSupported && !useCMSIncrementalMode(INJECTED_VMCONFIG) && length >= 0 && length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) {
127 Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options));
128 if (memory.notEqual(0)) {
129 if (logging(options)) {
130 printf("newArray: allocated new array at %p\n", memory.rawValue());
131 }
132 return verifyObject(
133 formatArray(hub, sizeInBytes, length, headerSize, memory, WordFactory.unsigned(arrayPrototypeMarkWord(INJECTED_VMCONFIG)), fillContents, false, null));
134 }
135 }
136 if (logging(options)) {
137 printf("newArray: calling new_array_c\n");
138 }
139
140 newArrayC(NEW_ARRAY_C, thread, hub, length);
141 handlePendingException(thread, true);
142 return verifyObject(getAndClearObjectResult(thread));
143 }
144
145 public static final ForeignCallDescriptor NEW_ARRAY_C = newDescriptor(NewArrayStub.class, "newArrayC", void.class, Word.class, KlassPointer.class, int.class);
146
|