From bd0949d81fd6d2742fc02c7cd9afd7d1e0f6a536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C3=B6=20Barany?= Date: Fri, 13 Sep 2024 11:10:22 +0200 Subject: [PATCH] Annotate Preconditions.checkIndex to inline the fast path on native image --- .../Target_jdk_internal_Preconditions.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_Preconditions.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_Preconditions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_Preconditions.java new file mode 100644 index 000000000000..44b2dbfff8fb --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_Preconditions.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.svm.core.jdk; + +import java.util.List; +import java.util.function.BiFunction; + +import com.oracle.svm.core.AlwaysInline; +import com.oracle.svm.core.NeverInline; +import com.oracle.svm.core.annotate.AnnotateOriginal; +import com.oracle.svm.core.annotate.TargetClass; + +@TargetClass(jdk.internal.util.Preconditions.class) +final class Target_jdk_internal_util_Preconditions { + @AnnotateOriginal + @AlwaysInline("fast path performance") + private static native int checkIndex(int index, int length, BiFunction, RuntimeException> oobef); + + @AnnotateOriginal + @AlwaysInline("fast path performance") + private static native long checkIndex(long index, long length, BiFunction, RuntimeException> oobef); + + @AnnotateOriginal + @NeverInline("slow path code size") + private static native RuntimeException outOfBoundsCheckIndex(BiFunction, ? extends RuntimeException> oobe, int index, int length); + + @AnnotateOriginal + @NeverInline("slow path code size") + private static native RuntimeException outOfBoundsCheckIndex(BiFunction, ? extends RuntimeException> oobe, long index, long length); +}