Skip to content

Commit

Permalink
Automatic merge of master into galahad
Browse files Browse the repository at this point in the history
  • Loading branch information
OracleLabsAutomation committed Jun 6, 2024
2 parents 64f8d90 + 9808ed4 commit adb937a
Show file tree
Hide file tree
Showing 29 changed files with 828 additions and 803 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind.Custom;

import java.io.FileDescriptor;
import java.io.IOException;

import com.oracle.svm.core.util.BasedOnJDKFile;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.c.function.CFunctionPointer;
import org.graalvm.nativeimage.c.struct.CPointerTo;
Expand All @@ -48,7 +46,7 @@
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.c.function.CEntryPointActions;
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
import com.oracle.svm.core.handles.PrimitiveArrayView;
import com.oracle.svm.core.util.BasedOnJDKFile;
import com.oracle.svm.core.windows.headers.FileAPI;
import com.oracle.svm.core.windows.headers.LibLoaderAPI;
import com.oracle.svm.core.windows.headers.WinBase;
Expand Down Expand Up @@ -84,10 +82,6 @@ static void setHandle(FileDescriptor descriptor, long handle) {
SubstrateUtil.cast(descriptor, Target_java_io_FileDescriptor.class).handle = handle;
}

static boolean outOfBounds(int off, int len, byte[] array) {
return off < 0 || len < 0 || array.length - off < len;
}

/** Return the error string for the last error, or a default message. */
public static String lastErrorString(String defaultMsg) {
int error = WinBase.GetLastError();
Expand Down Expand Up @@ -133,38 +127,6 @@ static boolean flush(int handle) {
return (result != 0);
}

@SuppressWarnings("unused")
static void writeBytes(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) throws IOException {
if (bytes == null) {
throw new NullPointerException();
} else if (WindowsUtils.outOfBounds(off, len, bytes)) {
throw new IndexOutOfBoundsException();
}
if (len == 0) {
return;
}

try (PrimitiveArrayView bytesPin = PrimitiveArrayView.createForReading(bytes)) {
CCharPointer curBuf = bytesPin.addressOfArrayElement(off);
UnsignedWord curLen = WordFactory.unsigned(len);
/** Temp fix until we complete FileDescriptor substitutions. */
int handle = FileAPI.GetStdHandle(FileAPI.STD_ERROR_HANDLE());

CIntPointer bytesWritten = UnsafeStackValue.get(CIntPointer.class);

int ret = FileAPI.WriteFile(handle, curBuf, curLen, bytesWritten, WordFactory.nullPointer());

if (ret == 0) {
throw new IOException(lastErrorString("Write error"));
}

int writtenCount = bytesWritten.read();
if (curLen.notEqual(writtenCount)) {
throw new IOException(lastErrorString("Write error"));
}
}
}

private static long performanceFrequency = 0L;
public static final long NANOSECS_PER_SEC = 1000000000L;
public static final int NANOSECS_PER_MILLISEC = 1000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
package com.oracle.svm.core;

import jdk.graal.compiler.word.BarrieredAccess;
import jdk.graal.compiler.word.Word;
import org.graalvm.word.Pointer;
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordFactory;
Expand All @@ -34,6 +32,9 @@
import com.oracle.svm.core.hub.LayoutEncoding;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.word.BarrieredAccess;
import jdk.graal.compiler.word.Word;

/**
* The methods in this class are mainly used to fill or copy Java heap memory. All methods guarantee
* at least some level of atomicity and honor the Java memory model if they are used as documented.
Expand Down Expand Up @@ -268,7 +269,7 @@ public static void copyBackward(Pointer from, Pointer to, UnsignedWord size) {
}

@Uninterruptible(reason = "Memory is on the heap, copying must not be interrupted.")
static void copyOnHeap(Object srcBase, UnsignedWord srcOffset, Object destBase, UnsignedWord destOffset, UnsignedWord size) {
public static void copyOnHeap(Object srcBase, UnsignedWord srcOffset, Object destBase, UnsignedWord destOffset, UnsignedWord size) {
Word fromPtr = Word.objectToUntrackedPointer(srcBase).add(srcOffset);
Word toPtr = Word.objectToUntrackedPointer(destBase).add(destOffset);
UnmanagedMemoryUtil.copy(fromPtr, toPtr, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.core;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
import static com.oracle.svm.core.option.RuntimeOptionKey.RuntimeOptionKeyFlag.RelevantForCompilationIsolates;

import java.util.ArrayList;
Expand Down Expand Up @@ -1307,11 +1308,24 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
}
};

@Option(help = "Determines if implicit exceptions are fatal if they don't have a stack trace.", type = OptionType.Debug)//
public static final RuntimeOptionKey<Boolean> ImplicitExceptionWithoutStacktraceIsFatal = new RuntimeOptionKey<>(false) {
@Override
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
super.onValueUpdate(values, oldValue, newValue);
if (ImageSingletons.contains(Options.class)) {
Options.singleton().implicitExceptionWithoutStacktraceIsFatal = newValue;
}
}
};

private volatile boolean loopOnFatalError;
private boolean implicitExceptionWithoutStacktraceIsFatal;

@Platforms(Platform.HOSTED_ONLY.class)
public Options() {
this.loopOnFatalError = Options.LoopOnFatalError.getValue();
this.implicitExceptionWithoutStacktraceIsFatal = Options.ImplicitExceptionWithoutStacktraceIsFatal.getValue();
}

@Fold
Expand All @@ -1322,5 +1336,10 @@ static Options singleton() {
public static boolean shouldLoopOnFatalError() {
return singleton().loopOnFatalError;
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public static boolean implicitExceptionWithoutStacktraceIsFatal() {
return singleton().implicitExceptionWithoutStacktraceIsFatal;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,6 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String ol
@Option(help = "Specifies the number of entries that diagnostic buffers have.", type = OptionType.Debug)//
public static final HostedOptionKey<Integer> DiagnosticBufferSize = new HostedOptionKey<>(30);

@Option(help = "Determines if implicit exceptions are fatal if they don't have a stack trace.", type = OptionType.Debug)//
public static final RuntimeOptionKey<Boolean> ImplicitExceptionWithoutStacktraceIsFatal = new RuntimeOptionKey<>(false);

@Option(help = "Determines if frame anchors are verified at run-time.", type = OptionType.Debug)//
public static final HostedOptionKey<Boolean> VerifyFrameAnchors = new HostedOptionKey<>(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private static long loadReferenceMapIndex(CodeInfo info, long entryOffset, int e
static final int FRAME_SIZE_STATUS_MASK = FRAME_SIZE_METHOD_START | FRAME_SIZE_ENTRY_POINT | FRAME_SIZE_HAS_CALLEE_SAVED_REGISTERS;

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static boolean decodeIsEntryPoint(long sizeEncoding) {
public static boolean decodeIsEntryPoint(long sizeEncoding) {
assert sizeEncoding != INVALID_SIZE_ENCODING;
return (sizeEncoding & FRAME_SIZE_ENTRY_POINT) != 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.oracle.svm.core.snippets.SnippetRuntime;
import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
import com.oracle.svm.core.util.ArrayUtil;

import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.graph.NodeClass;
Expand All @@ -50,7 +51,6 @@
import jdk.graal.compiler.nodes.StructuredGraph;
import jdk.graal.compiler.nodes.ValueNode;
import jdk.graal.compiler.nodes.extended.ForeignCallWithExceptionNode;
import jdk.graal.compiler.nodes.java.ArrayLengthNode;
import jdk.graal.compiler.nodes.spi.Lowerable;
import jdk.graal.compiler.nodes.spi.LoweringTool;
import jdk.graal.compiler.options.OptionValues;
Expand Down Expand Up @@ -88,25 +88,25 @@ private static void doArraycopy(Object fromArray, int fromIndex, Object toArray,

if (LayoutEncoding.isPrimitiveArray(fromLayoutEncoding)) {
if (fromArray == toArray && fromIndex < toIndex) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
ArrayUtil.boundsCheckInSnippet(fromArray, fromIndex, toArray, toIndex, length);
JavaMemoryUtil.copyPrimitiveArrayBackward(fromArray, fromIndex, fromArray, toIndex, length, fromLayoutEncoding);
return;
} else if (fromHub == toHub) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
ArrayUtil.boundsCheckInSnippet(fromArray, fromIndex, toArray, toIndex, length);
JavaMemoryUtil.copyPrimitiveArrayForward(fromArray, fromIndex, toArray, toIndex, length, fromLayoutEncoding);
return;
}
} else if (LayoutEncoding.isObjectArray(fromLayoutEncoding)) {
if (fromArray == toArray && fromIndex < toIndex) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
ArrayUtil.boundsCheckInSnippet(fromArray, fromIndex, toArray, toIndex, length);
JavaMemoryUtil.copyObjectArrayBackward(fromArray, fromIndex, fromArray, toIndex, length, fromLayoutEncoding);
return;
} else if (fromHub == toHub) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
ArrayUtil.boundsCheckInSnippet(fromArray, fromIndex, toArray, toIndex, length);
JavaMemoryUtil.copyObjectArrayForward(fromArray, fromIndex, toArray, toIndex, length, fromLayoutEncoding);
return;
} else if (LayoutEncoding.isObjectArray(toHub.getLayoutEncoding())) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
ArrayUtil.boundsCheckInSnippet(fromArray, fromIndex, toArray, toIndex, length);
if (DynamicHub.toClass(toHub).isAssignableFrom(DynamicHub.toClass(fromHub))) {
JavaMemoryUtil.copyObjectArrayForward(fromArray, fromIndex, toArray, toIndex, length, fromLayoutEncoding);
} else {
Expand All @@ -118,12 +118,6 @@ private static void doArraycopy(Object fromArray, int fromIndex, Object toArray,
throw new ArrayStoreException();
}

private static void boundsCheck(Object fromArray, int fromIndex, Object toArray, int toIndex, int length) {
if (fromIndex < 0 || toIndex < 0 || length < 0 || fromIndex > ArrayLengthNode.arrayLength(fromArray) - length || toIndex > ArrayLengthNode.arrayLength(toArray) - length) {
throw new ArrayIndexOutOfBoundsException();
}
}

static final class SubstrateArrayCopyLowering implements NodeLoweringProvider<ArrayCopyNode> {
@Override
public void lower(ArrayCopyNode node, LoweringTool tool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import jdk.graal.compiler.nodes.extended.BoxNode;
import jdk.graal.compiler.nodes.extended.FixedValueAnchorNode;
import jdk.graal.compiler.nodes.extended.GuardingNode;
import jdk.graal.compiler.nodes.extended.StateSplitProxyNode;
import jdk.graal.compiler.nodes.extended.UnboxNode;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import jdk.graal.compiler.nodes.java.ExceptionObjectNode;
Expand Down Expand Up @@ -372,10 +371,4 @@ protected <T extends WithExceptionNode> T appendWithUnwind(T withExceptionNode,

return withExceptionNode;
}

public void appendStateSplitProxy() {
StateSplitProxyNode proxy = new StateSplitProxyNode();
append(proxy);
proxy.setStateAfter(frameState.create(bci(), proxy));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void popFrame() {
popFramesIncluding(frameCount);
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public void popFramesIncluding(int frame) {
assert frame > 0 && frame <= frameCount;
int previousTop = top;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,13 @@
*/
package com.oracle.svm.core.jni;

import java.lang.reflect.Array;

import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.word.PointerBase;
import org.graalvm.word.WordBase;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.StaticFieldsSupport;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.handles.PrimitiveArrayView;
import com.oracle.svm.core.jni.access.JNIAccessibleField;
import com.oracle.svm.core.jni.access.JNINativeLinkage;
import com.oracle.svm.core.jni.headers.JNIEnvironment;
import com.oracle.svm.core.jni.headers.JNIFieldId;
import com.oracle.svm.core.jni.headers.JNIObjectHandle;

import jdk.internal.misc.Unsafe;
import jdk.vm.ci.meta.JavaKind;

/**
* Helper code that is used in generated JNI code via {@code JNIGraphKit}.
*/
Expand All @@ -58,6 +45,7 @@ static int nativeCallPrologue() {
return JNIObjectHandles.pushLocalFrame(JNIObjectHandles.NATIVE_CALL_MIN_LOCAL_HANDLE_CAPACITY);
}

@Uninterruptible(reason = "Must not throw any exceptions - otherwise, we might leak memory.")
static void nativeCallEpilogue(int handleFrame) {
JNIObjectHandles.popLocalFramesIncluding(handleFrame);
}
Expand All @@ -76,72 +64,23 @@ static Object unboxHandle(JNIObjectHandle handle) {
return JNIObjectHandles.getObject(handle);
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static WordBase getFieldOffsetFromId(JNIFieldId fieldId) {
return JNIAccessibleField.getOffsetFromId(fieldId);
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static Object getStaticPrimitiveFieldsArray() {
return StaticFieldsSupport.getStaticPrimitiveFields();
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static Object getStaticObjectFieldsArray() {
return StaticFieldsSupport.getStaticObjectFields();
}

@Uninterruptible(reason = "Must not throw any exceptions.")
static void setPendingException(Throwable t) {
JNIThreadLocalPendingException.set(t);
}

@Uninterruptible(reason = "Must not throw any exceptions.")
static Throwable getAndClearPendingException() {
Throwable t = JNIThreadLocalPendingException.get();
JNIThreadLocalPendingException.clear();
return t;
}

@Uninterruptible(reason = "Must not throw any exceptions, except for the pending exception.")
static void rethrowPendingException() throws Throwable {
Throwable t = getAndClearPendingException();
if (t != null) {
throw t;
}
}

static PointerBase createArrayViewAndGetAddress(Object array, CCharPointer isCopy) throws Throwable {
if (array.getClass().isArray()) {
PrimitiveArrayView ref = JNIThreadLocalPrimitiveArrayViews.createArrayView(array);
if (isCopy.isNonNull()) {
isCopy.write(ref.isCopy() ? (byte) 1 : (byte) 0);
}
return ref.addressOfArrayElement(0);
}
return WordFactory.nullPointer();
}

static void destroyNewestArrayViewByAddress(PointerBase address, int mode) throws Throwable {
JNIThreadLocalPrimitiveArrayViews.destroyNewestArrayViewByAddress(address, mode);
}

static void getPrimitiveArrayRegion(JavaKind elementKind, Object array, int start, int count, PointerBase buffer) {
if (start < 0 || count < 0 || start + count > Array.getLength(array)) {
throw new ArrayIndexOutOfBoundsException();
}
if (count > 0) {
long offset = ConfigurationValues.getObjectLayout().getArrayElementOffset(elementKind, start);
int elementSize = ConfigurationValues.getObjectLayout().sizeInBytes(elementKind);
Unsafe.getUnsafe().copyMemory(array, offset, null, buffer.rawValue(), count * elementSize);
}
}

static void setPrimitiveArrayRegion(JavaKind elementKind, Object array, int start, int count, PointerBase buffer) {
if (start < 0 || count < 0 || start + count > Array.getLength(array)) {
throw new ArrayIndexOutOfBoundsException();
}
if (count > 0) {
long offset = ConfigurationValues.getObjectLayout().getArrayElementOffset(elementKind, start);
int elementSize = ConfigurationValues.getObjectLayout().sizeInBytes(elementKind);
Unsafe.getUnsafe().copyMemory(null, buffer.rawValue(), array, offset, count * elementSize);
}
}
}
Loading

0 comments on commit adb937a

Please sign in to comment.