Skip to content

Commit

Permalink
[GR-46613] Update to JDK 22+8
Browse files Browse the repository at this point in the history
PullRequest: graal/15232
  • Loading branch information
zapster committed Aug 22, 2023
2 parents 4c7d073 + f98bcfd commit e7b40b1
Show file tree
Hide file tree
Showing 11 changed files with 676 additions and 77 deletions.
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b13-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b13-sulong", "platformspecific": true },

"oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "2", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}
"oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "8", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}
},

"eclipse": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import com.oracle.svm.core.heap.UnknownPrimitiveField;
import com.oracle.svm.core.jdk.JDK19OrLater;
import com.oracle.svm.core.jdk.JDK21OrLater;
import com.oracle.svm.core.jdk.JDK22OrLater;
import com.oracle.svm.core.jdk.Resources;
import com.oracle.svm.core.meta.SharedType;
import com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils;
Expand Down Expand Up @@ -1357,6 +1358,10 @@ private static Class<?> forName(String name, boolean initialize, ClassLoader loa
return result;
}

@KeepOriginal
@TargetElement(onlyWith = JDK22OrLater.class)
public static native Class<?> forPrimitiveName(String primitiveName);

@KeepOriginal
private native Package getPackage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final class Target_jdk_jfr_internal_periodic_JVMEventTask {
// Only present in JDKs without JDK-8268398
@TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = JDK17OrEarlier.class)
@Platforms(LINUX.class)
final class Target_jdk_jfr_internal_Utils {
final class Target_jdk_jfr_internal_Utils_JDK17 {
@Alias //
@RecomputeFieldValue(kind = Kind.Reset) //
private static Target_jdk_internal_platform_Metrics[] metrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.sun.management.internal.PlatformMBeanProviderImpl;

import jdk.jfr.Configuration;
import jdk.jfr.internal.JVM;
import jdk.jfr.internal.jfc.JFC;

/**
Expand Down Expand Up @@ -158,7 +157,7 @@ public void afterRegistration(AfterRegistrationAccess access) {

// Initialize some parts of JFR/JFC at image build time.
List<Configuration> knownConfigurations = JFC.getConfigurations();
JVM.getJVM().createNativeJFR();
JfrJdkCompatibility.createNativeJFR();

ImageSingletons.add(JfrManager.class, new JfrManager(HOSTED_ENABLED));
ImageSingletons.add(SubstrateJVM.class, new SubstrateJVM(knownConfigurations));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (c) 2023, 2023, 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.jfr;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.Duration;

import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jdk.JDK21OrEarlier;
import com.oracle.svm.core.jdk.JDK22OrLater;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

import jdk.jfr.Recording;
import jdk.jfr.internal.JVM;
import jdk.jfr.internal.JVMSupport;

/**
* Compatibility class to handle incompatible changes between JDK 21 and JDK 22. Once support for
* JDKs prior to 22 is dropped, these the methods can be called directly and the substitutions can
* go away.
*/
@SuppressWarnings("unused")

public final class JfrJdkCompatibility {
private JfrJdkCompatibility() {
}

public static String makeFilename(Recording recording) {
if (JavaVersionUtil.JAVA_SPEC >= 22) {
return Target_jdk_jfr_internal_JVMSupport.makeFilename(recording);
} else {
return Target_jdk_jfr_internal_Utils.makeFilename(recording);
}
}

public static String formatTimespan(Duration dValue, String separation) {
if (JavaVersionUtil.JAVA_SPEC >= 22) {
return Target_jdk_jfr_internal_util_ValueFormatter.formatTimespan(dValue, separation);
} else {
return Target_jdk_jfr_internal_Utils.formatTimespan(dValue, separation);
}
}

@Platforms(Platform.HOSTED_ONLY.class)
public static void createNativeJFR() {
try {
if (JavaVersionUtil.JAVA_SPEC >= 22) {
Method createJFR = ReflectionUtil.lookupMethod(JVMSupport.class, "createJFR");
createJFR.invoke(null);
} else {
Method createNativeJFR = ReflectionUtil.lookupMethod(JVM.class, "createNativeJFR");
createNativeJFR.invoke(getJVMOrNull());
}
} catch (ReflectiveOperationException | ClassCastException e) {
throw VMError.shouldNotReachHere(e);
}
}

@Platforms(Platform.HOSTED_ONLY.class)
public static void retransformClasses(Class<?>[] classes) {
try {
// call JVM.retransformClasses(classes)
Method retransformClasses = ReflectionUtil.lookupMethod(JVM.class, "retransformClasses", Class[].class);
retransformClasses.invoke(getJVMOrNull(), (Object) classes);
} catch (ReflectiveOperationException | ClassCastException e) {
throw VMError.shouldNotReachHere(e);
}
}

/**
* Gets a {@link JVM} object or {@code null} in case of JDK 22+, where the methods of
* {@link JVM} are static (JDK-8310661).
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static JVM getJVMOrNull() throws IllegalAccessException, InvocationTargetException {
if (JavaVersionUtil.JAVA_SPEC >= 22) {
return null;
} else {
Method getJVM = ReflectionUtil.lookupMethod(JVM.class, "getJVM");
return (JVM) getJVM.invoke(null);
}
}
}

@TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = {JDK21OrEarlier.class, HasJfrSupport.class})
final class Target_jdk_jfr_internal_Utils {
@Alias
public static native String makeFilename(Recording recording);

@Alias
public static native String formatTimespan(Duration dValue, String separation);
}

@TargetClass(className = "jdk.jfr.internal.JVMSupport", onlyWith = {JDK22OrLater.class, HasJfrSupport.class})
final class Target_jdk_jfr_internal_JVMSupport {
@Alias
public static native String makeFilename(Recording recording);
}

@TargetClass(className = "jdk.jfr.internal.util.ValueFormatter", onlyWith = {JDK22OrLater.class, HasJfrSupport.class})
final class Target_jdk_jfr_internal_util_ValueFormatter {
@Alias
public static native String formatTimespan(Duration dValue, String separation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import jdk.jfr.internal.OldObjectSample;
import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.SecuritySupport;
import jdk.jfr.internal.Utils;
import jdk.jfr.internal.jfc.JFC;

/**
Expand Down Expand Up @@ -240,7 +239,7 @@ private static void initRecording() {
recording.scheduleStart(dDelay);

msg.append("Recording " + recording.getId() + " scheduled to start in ");
msg.append(Utils.formatTimespan(dDelay, " "));
msg.append(JfrJdkCompatibility.formatTimespan(dDelay, " "));
msg.append(".");
} else {
recording.start();
Expand Down Expand Up @@ -276,7 +275,7 @@ private static SecuritySupport.SafePath resolvePath(Recording recording, String
}

private static SecuritySupport.SafePath makeGenerated(Recording recording, Path directory) {
return new SecuritySupport.SafePath(directory.toAbsolutePath().resolve(Utils.makeFilename(recording)).normalize());
return new SecuritySupport.SafePath(directory.toAbsolutePath().resolve(JfrJdkCompatibility.makeFilename(recording)).normalize());
}

private static String getPath(SecuritySupport.SafePath path) {
Expand Down
Loading

0 comments on commit e7b40b1

Please sign in to comment.