Skip to content

Commit fd06097

Browse files
committed
[GR-51436] Add @BasedOnJDKFile annotation
PullRequest: graal/16861
2 parents 8b36b74 + 1fddbfe commit fd06097

File tree

8 files changed

+341
-7
lines changed

8 files changed

+341
-7
lines changed

compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/processor/AbstractProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public void createProviderFile(String providerClassName, String serviceClassName
342342
* Determines if a given exception is (most likely) caused by
343343
* <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599">Bug 367599</a>.
344344
*/
345-
private static boolean isBug367599(Throwable t) {
345+
protected static boolean isBug367599(Throwable t) {
346346
if (t instanceof FilerException) {
347347
for (StackTraceElement ste : t.getStackTrace()) {
348348
if (ste.toString().contains("org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.create")) {

substratevm/mx.substratevm/suite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@
251251
"compiler:GRAAL_PROCESSOR"
252252
],
253253
"requires" : [
254-
"java.compiler" # javax.annotation.processing.*
254+
"java.compiler", # javax.annotation.processing.*
255+
"jdk.compiler", # com.sun.source.util.*
255256
],
256257
"javaCompliance" : "21+",
257258
"checkstyle" : "com.oracle.svm.core",

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.FileDescriptor;
3030
import java.io.IOException;
3131

32+
import com.oracle.svm.core.util.BasedOnJDKFile;
3233
import org.graalvm.nativeimage.StackValue;
3334
import org.graalvm.nativeimage.c.function.CFunctionPointer;
3435
import org.graalvm.nativeimage.c.struct.CPointerTo;
@@ -170,6 +171,8 @@ static void writeBytes(FileDescriptor descriptor, byte[] bytes, int off, int len
170171

171172
/** Retrieve a nanosecond counter for elapsed time measurement. */
172173
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
174+
@BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L970-L977")
175+
@BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L1075-L1081")
173176
public static long getNanoCounter() {
174177
if (performanceFrequency == 0L) {
175178
CLongPointer count = StackValue.get(CLongPointer.class);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/amd64/AMD64LibCHelper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@
3636
import org.graalvm.nativeimage.c.type.CCharPointer;
3737
import org.graalvm.word.PointerBase;
3838

39-
import jdk.graal.compiler.lir.SyncPort;
39+
import com.oracle.svm.core.util.BasedOnJDKFile;
4040

41-
// @formatter:off
42-
@SyncPort(from = "https://github.com/openjdk/jdk/blob/34f85ee94e8b45bcebbf8ba52a38c92a7185b54a/src/hotspot/cpu/x86/vm_version_x86.hpp#L40-L304",
43-
sha1 = "5cc04c08555379223cc02a15774159076d3cdf1d")
4441
/*
4542
* To be kept in sync with:
4643
* - substratevm/src/com.oracle.svm.native.libchelper/include/amd64hotspotcpuinfo.h
4744
* - substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c
4845
*/
49-
// @formatter:on
46+
@BasedOnJDKFile("src/hotspot/cpu/x86/vm_version_x86.hpp#L40-L304")
5047
@CLibrary(value = "libchelper", requireStatic = true)
5148
public class AMD64LibCHelper {
5249
@Platforms(Platform.AMD64.class)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDKLatest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.core.jni.headers;
2626

27+
import com.oracle.svm.core.util.BasedOnJDKFile;
2728
import org.graalvm.nativeimage.c.CContext;
2829
import org.graalvm.nativeimage.c.constant.CConstant;
2930

@@ -46,6 +47,7 @@ public final class JNIVersionJDKLatest {
4647
* gets available, the "value" property of the CConstant annotation below must be removed.
4748
*/
4849
@CConstant(value = "JNI_VERSION_21")
50+
@BasedOnJDKFile("src/java.base/share/native/include/jni.h#L1985-L1996")
4951
public static native int JNI_VERSION_LATEST();
5052

5153
// Checkstyle: resume
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2024, 2024, 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.util;
26+
27+
import java.lang.annotation.ElementType;
28+
import java.lang.annotation.Repeatable;
29+
import java.lang.annotation.Retention;
30+
import java.lang.annotation.RetentionPolicy;
31+
import java.lang.annotation.Target;
32+
33+
import org.graalvm.nativeimage.Platform;
34+
import org.graalvm.nativeimage.Platforms;
35+
36+
/**
37+
* Documents that the element is based on a JDK source file. This is mainly useful for non-Java
38+
* sources like C++ files. For Java classes, {@link BasedOnJDKClass} might be more appropriate.
39+
*/
40+
@Repeatable(BasedOnJDKFile.List.class)
41+
@Retention(RetentionPolicy.RUNTIME)
42+
@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD})
43+
@Platforms(Platform.HOSTED_ONLY.class)
44+
public @interface BasedOnJDKFile {
45+
46+
/**
47+
* Path to the source file relative to the repository root (usually
48+
* <a href="https://github.com/openjdk/jdk">openjdk</a>). The path elements must be separated by
49+
* slashes ({@code /}) and since it is a relative path, it must not start with a slash.
50+
*
51+
* To specify a line range, a suffix of the form {@code #L[0-9]+-L[0-9]+} might be added. Full
52+
* example:
53+
*
54+
* <pre>
55+
* &#64;BasedOnJDKFile("src/hotspot/cpu/x86/vm_version_x86.hpp#L40-L304")
56+
* </pre>
57+
*
58+
* The path and line numbers always apply to the latest supported JDK version. That version can
59+
* be retrieved from the {@code jdks.oraclejdk-latest} entry from {@code common.json} in the
60+
* root of this repository, or by looking up the latest version in the
61+
* {@code JVMCI_MIN_VERSIONS} map in {@link jdk.graal.compiler.hotspot.JVMCIVersionCheck}. At
62+
* the time of writing this is {@code jdk-23+8} (formatted as a git tag as used by the openjdk).
63+
* That information can also be used to view the respective line range on GitHub via
64+
* {@code https://github.com/openjdk/jdk/blob/<version-tag>/<value>}. For the example above, it
65+
* would translate to <a href=
66+
* "https://github.com/openjdk/jdk/blob/jdk-23+8/src/hotspot/cpu/x86/vm_version_x86.hpp#L40-L304">
67+
* {@code https://github.com/openjdk/jdk/blob/jdk-23+8/src/hotspot/cpu/x86/vm_version_x86.hpp#L40-L304}</a>
68+
*/
69+
String value();
70+
71+
/**
72+
* Support for making {@link BasedOnJDKFile} {@linkplain Repeatable repeatable}.
73+
*/
74+
@Retention(RetentionPolicy.RUNTIME)
75+
@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD})
76+
@Platforms(Platform.HOSTED_ONLY.class)
77+
@interface List {
78+
BasedOnJDKFile[] value();
79+
}
80+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
com.oracle.svm.processor.AutomaticallyRegisteredFeatureProcessor
22
com.oracle.svm.processor.AutomaticallyRegisteredImageSingletonProcessor
3+
com.oracle.svm.processor.BasedOnJDKFileProcessor

0 commit comments

Comments
 (0)