Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,4 @@ public static Unsafe getUnsafe() {
}
return UNSAFE;
}

@SuppressWarnings("deprecation") // deprecated since JDK 15
public static boolean shouldBeInitialized(Class<?> c) {
return UNSAFE.shouldBeInitialized(c);
}

@SuppressWarnings("deprecation") // deprecated since JDK 15
public static void ensureClassInitialized(Class<?> c) {
UNSAFE.ensureClassInitialized(c);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
package org.graalvm.compiler.word;

import static org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.getUnsafe;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -50,6 +48,7 @@
import org.graalvm.compiler.nodes.calc.XorNode;
import org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType;
import org.graalvm.compiler.nodes.memory.address.AddressNode.Address;
import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
import org.graalvm.word.ComparableWord;
import org.graalvm.word.LocationIdentity;
import org.graalvm.word.Pointer;
Expand All @@ -63,7 +62,7 @@

public abstract class Word implements SignedWord, UnsignedWord, Pointer {

private static final Unsafe UNSAFE = getUnsafe();
private static final Unsafe UNSAFE = GraalUnsafeAccess.getUnsafe();

static {
BoxFactoryImpl.initialize();
Expand Down
43 changes: 23 additions & 20 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@
"java.xml.crypto",
"jdk.jfr",
"jdk.management",
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
"jdk.internal.org.objectweb.asm",
"sun.reflect.annotation",
"sun.security.jca",
Expand Down Expand Up @@ -604,9 +604,11 @@
"dependencies": [
"com.oracle.svm.hosted",
],
"requires" : [
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
],
},
"checkstyle": "com.oracle.svm.core",
"workingSets": "SVM",
"annotationProcessors": [
Expand Down Expand Up @@ -665,12 +667,12 @@
"SVM",
],
"requires": [
"jdk.unsupported",
"java.compiler",
"jdk.jfr",
],
"requiresConcealed": {
"java.base": [
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
"sun.security.jca",
],
},
Expand Down Expand Up @@ -769,11 +771,9 @@
"dependencies" : [
"compiler:GRAAL"
],
"requires" : [
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
"jdk.internal.ref",
"sun.nio.ch",
],
Expand All @@ -792,10 +792,10 @@
"com.oracle.svm.hosted",
"truffle:TRUFFLE_API",
],
"requires" : [
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.runtime",
],
Expand Down Expand Up @@ -862,9 +862,11 @@
"dependencies": [
"com.oracle.svm.graal",
],
"requires" : [
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
],
},
"checkstyle": "com.oracle.svm.hosted",
"javaCompliance": "11+",
"annotationProcessors": [
Expand Down Expand Up @@ -963,9 +965,11 @@
"com.oracle.svm.graal",
"compiler:GRAAL"
],
"requires" : [
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
],
},
"checkstyle" : "com.oracle.svm.hosted",
"javaCompliance": "11+",
"annotationProcessors": [
Expand Down Expand Up @@ -1276,7 +1280,6 @@
"com.oracle.objectfile.macho",
],

"requires" : ["jdk.unsupported"],
"requiresConcealed" : {
"java.base" : [
"sun.nio.ch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
package com.oracle.objectfile;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
Expand All @@ -53,7 +51,6 @@
import com.oracle.objectfile.macho.MachOObjectFile;
import com.oracle.objectfile.pecoff.PECoffObjectFile;

import sun.misc.Unsafe;
import sun.nio.ch.DirectBuffer;

/**
Expand Down Expand Up @@ -1275,46 +1272,14 @@ public final void write(FileChannel outputChannel) {
try {
writeBuffer(sortedObjectFileElements, buffer);
} finally {
cleanBuffer(buffer); // unmap immediately
// unmap immediately
((DirectBuffer) buffer).cleaner().clean();
}
} catch (IOException | ReflectiveOperationException e) {
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static void cleanBuffer(ByteBuffer buffer) throws ReflectiveOperationException {
try {
/*
* Trying to use sun.misc.Unsafe.invokeCleaner as the first approach restores forward
* compatibility to Java > 8. If it fails we know we are on Java 8 where we can use a
* non-forward compatible way of forcing to clean the ByteBuffer.
*/
Method invokeCleanerMethod = Unsafe.class.getMethod("invokeCleaner", ByteBuffer.class);
invokeCleanerMethod.invoke(UNSAFE, buffer);
} catch (NoSuchMethodException e) {
/* On Java 8 we have to use the non-forward compatible approach. */
((DirectBuffer) buffer).cleaner().clean();
}
}

private static final Unsafe UNSAFE = initUnsafe();

@SuppressWarnings("restriction")
private static Unsafe initUnsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException se) {
Field theUnsafe = null;
try {
theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (ReflectiveOperationException e) {
throw new RuntimeException("exception while trying to get Unsafe", e);
}
}
}

/*
* We keep track of what build dependencies have been created, so that the factory in
* BuildDependency can query for duplicates. This logic is package-access: it is not needed by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.graalvm.compiler.options.OptionStability;
import org.graalvm.compiler.options.OptionType;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.nativeimage.ImageSingletons;

Expand All @@ -61,6 +60,8 @@
import com.oracle.svm.core.thread.VMOperationControl;
import com.oracle.svm.core.util.UserError;

import jdk.internal.misc.Unsafe;

public class SubstrateOptions {

@Option(help = "When true, compiler graphs are parsed only once before static analysis. When false, compiler graphs are parsed for static analysis and again for AOT compilation.")//
Expand Down Expand Up @@ -694,21 +695,20 @@ public ReportingSupport(String reportingPath) {
public static int getPageSize() {
int value = PageSize.getValue();
if (value == 0) {
return hostPageSize;
try {
/*
* On JDK 17 and later, this is just a final field access that can never fail. But
* on JDK 11, it is a native method call with some corner cases that can throw an
* exception.
*/
return Unsafe.getUnsafe().pageSize();
} catch (IllegalArgumentException e) {
return 4096;
}
}
return value;
}

private static int hostPageSize = getHostPageSize();

private static int getHostPageSize() {
try {
return GraalUnsafeAccess.getUnsafe().pageSize();
} catch (IllegalArgumentException e) {
return 4096;
}
}

@Option(help = "Specifies how many details are printed for certain diagnostic thunks, e.g.: 'DumpThreads:1,DumpRegisters:2'. " +
"A value of 1 will result in the maximum amount of information, higher values will print less information. " +
"By default, the most detailed output is enabled for all diagnostic thunks. Wildcards (*) are supported in the name of the diagnostic thunk.", type = Expert)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.function.CFunctionPointer;
Expand All @@ -39,7 +38,7 @@
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
import com.oracle.svm.core.util.VMError;

import sun.misc.Unsafe;
import jdk.internal.misc.Unsafe;

/**
* Information about the runtime class initialization state of a {@link DynamicHub class}, and
Expand All @@ -53,8 +52,6 @@
@InternalVMMethod
public final class ClassInitializationInfo {

private static final Unsafe UNSAFE = GraalUnsafeAccess.getUnsafe();

/**
* Singleton for classes that are already initialized during image building and do not need
* class initialization at runtime, but have {@code <clinit>} methods.
Expand Down Expand Up @@ -344,7 +341,7 @@ private void setInitializationStateAndNotify(InitState state) {
this.initState = state;
this.initThread = null;
/* Make sure previous stores are all done, notably the initState. */
UNSAFE.storeFence();
Unsafe.getUnsafe().storeFence();

if (initCondition != null) {
initCondition.signalAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.graalvm.compiler.core.common.util.TypeConversion;
import org.graalvm.compiler.options.Option;
import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
import org.graalvm.compiler.word.BarrieredAccess;
import org.graalvm.compiler.word.Word;
import org.graalvm.nativeimage.CurrentIsolate;
Expand Down Expand Up @@ -85,13 +84,13 @@
import com.oracle.svm.core.util.RingBuffer;
import com.oracle.svm.core.util.VMError;

import jdk.internal.misc.Unsafe;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.meta.DeoptimizationAction;
import jdk.vm.ci.meta.DeoptimizationReason;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.SpeculationLog.SpeculationReason;
import sun.misc.Unsafe;

/**
* Performs deoptimization. The method to deoptimize (= the source method) is either a specialized
Expand Down Expand Up @@ -149,8 +148,6 @@
*/
public final class Deoptimizer {

private static final Unsafe UNSAFE = GraalUnsafeAccess.getUnsafe();

private static final RingBuffer<char[]> recentDeoptimizationEvents = new RingBuffer<>();

private static final int actionShift = 0;
Expand Down Expand Up @@ -962,7 +959,7 @@ private Object materializeObject(int virtualObjectId, FrameInfoQueryResult sourc
curIdx = 2;
} else {
try {
obj = UNSAFE.allocateInstance(DynamicHub.toClass(hub));
obj = Unsafe.getUnsafe().allocateInstance(DynamicHub.toClass(hub));
} catch (InstantiationException ex) {
throw VMError.shouldNotReachHere(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.graalvm.compiler.replacements.SnippetTemplate.Arguments;
import org.graalvm.compiler.replacements.SnippetTemplate.SnippetInfo;
import org.graalvm.compiler.replacements.Snippets;
import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
import org.graalvm.compiler.word.BarrieredAccess;
import org.graalvm.word.LocationIdentity;
import org.graalvm.word.WordFactory;
Expand All @@ -67,6 +66,8 @@
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
import com.oracle.svm.core.util.NonmovableByteArrayReader;

import jdk.internal.misc.Unsafe;

public final class SubstrateObjectCloneSnippets extends SubstrateTemplates implements Snippets {
private static final SubstrateForeignCallDescriptor CLONE = SnippetRuntime.findForeignCall(SubstrateObjectCloneSnippets.class, "doClone", true, LocationIdentity.any());
private static final SubstrateForeignCallDescriptor[] FOREIGN_CALLS = new SubstrateForeignCallDescriptor[]{CLONE};
Expand Down Expand Up @@ -95,8 +96,7 @@ private static Object doClone(Object original) throws CloneNotSupportedException
}
return newArray;
} else {
sun.misc.Unsafe unsafe = GraalUnsafeAccess.getUnsafe();
Object result = unsafe.allocateInstance(DynamicHub.toClass(hub));
Object result = Unsafe.getUnsafe().allocateInstance(DynamicHub.toClass(hub));
int firstFieldOffset = ConfigurationValues.getObjectLayout().getFirstFieldOffset();
int curOffset = firstFieldOffset;

Expand Down
Loading