1 /* 2 * Copyright (c) 2019, 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 24 25 package org.graalvm.compiler.hotspot.amd64; 26 27 import org.graalvm.compiler.api.replacements.Snippet; 28 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; 29 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; 30 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 31 import org.graalvm.compiler.hotspot.stubs.SnippetStub; 32 import org.graalvm.compiler.options.OptionValues; 33 import org.graalvm.compiler.replacements.nodes.ArrayEqualsNode; 34 import org.graalvm.compiler.replacements.nodes.ArrayRegionEqualsNode; 35 import jdk.internal.vm.compiler.word.Pointer; 36 37 import jdk.vm.ci.meta.JavaKind; 38 39 public final class AMD64ArrayEqualsStub extends SnippetStub { 40 41 public static final ForeignCallDescriptor STUB_BOOLEAN_ARRAY_EQUALS = new ForeignCallDescriptor( 42 "booleanArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 43 public static final ForeignCallDescriptor STUB_BYTE_ARRAY_EQUALS = new ForeignCallDescriptor( 44 "byteArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 45 public static final ForeignCallDescriptor STUB_CHAR_ARRAY_EQUALS = new ForeignCallDescriptor( 46 "charArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 47 public static final ForeignCallDescriptor STUB_SHORT_ARRAY_EQUALS = new ForeignCallDescriptor( 48 "shortArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 49 public static final ForeignCallDescriptor STUB_INT_ARRAY_EQUALS = new ForeignCallDescriptor( 50 "intArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 51 public static final ForeignCallDescriptor STUB_LONG_ARRAY_EQUALS = new ForeignCallDescriptor( 52 "longArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 53 public static final ForeignCallDescriptor STUB_FLOAT_ARRAY_EQUALS = new ForeignCallDescriptor( 54 "floatArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 55 public static final ForeignCallDescriptor STUB_DOUBLE_ARRAY_EQUALS = new ForeignCallDescriptor( 56 "doubleArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class); 57 58 public static final ForeignCallDescriptor STUB_BYTE_ARRAY_EQUALS_DIRECT = new ForeignCallDescriptor( 59 "byteArraysEqualsDirect", boolean.class, Pointer.class, Pointer.class, int.class); 60 public static final ForeignCallDescriptor STUB_CHAR_ARRAY_EQUALS_DIRECT = new ForeignCallDescriptor( 61 "charArraysEqualsDirect", boolean.class, Pointer.class, Pointer.class, int.class); 62 public static final ForeignCallDescriptor STUB_CHAR_ARRAY_EQUALS_BYTE_ARRAY = new ForeignCallDescriptor( 63 "charArrayEqualsByteArray", boolean.class, Pointer.class, Pointer.class, int.class); 64 65 public AMD64ArrayEqualsStub(ForeignCallDescriptor foreignCallDescriptor, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) { 66 super(foreignCallDescriptor.getName(), options, providers, linkage); 67 } 68 69 @Snippet 70 private static boolean booleanArraysEquals(Pointer array1, Pointer array2, int length) { 71 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Boolean); 72 } 73 74 @Snippet 75 private static boolean byteArraysEquals(Pointer array1, Pointer array2, int length) { 76 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Byte); 77 } 78 79 @Snippet 80 private static boolean charArraysEquals(Pointer array1, Pointer array2, int length) { 81 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Char); 82 } 83 84 @Snippet 85 private static boolean shortArraysEquals(Pointer array1, Pointer array2, int length) { 86 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Short); 87 } 88 89 @Snippet 90 private static boolean intArraysEquals(Pointer array1, Pointer array2, int length) { 91 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Int); 92 } 93 94 @Snippet 95 private static boolean longArraysEquals(Pointer array1, Pointer array2, int length) { 96 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Long); 97 } 98 99 @Snippet 100 private static boolean floatArraysEquals(Pointer array1, Pointer array2, int length) { 101 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Float); 102 } 103 104 @Snippet 105 private static boolean doubleArraysEquals(Pointer array1, Pointer array2, int length) { 106 return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Double); 107 } 108 109 @Snippet 110 private static boolean byteArraysEqualsDirect(Pointer array1, Pointer array2, int length) { 111 return ArrayRegionEqualsNode.regionEquals(array1, array2, length, JavaKind.Byte, JavaKind.Byte); 112 } 113 114 @Snippet 115 private static boolean charArraysEqualsDirect(Pointer array1, Pointer array2, int length) { 116 return ArrayRegionEqualsNode.regionEquals(array1, array2, length, JavaKind.Char, JavaKind.Char); 117 } 118 119 @Snippet 120 private static boolean charArrayEqualsByteArray(Pointer array1, Pointer array2, int length) { 121 return ArrayRegionEqualsNode.regionEquals(array1, array2, length, JavaKind.Char, JavaKind.Byte); 122 } 123 }