From 6798fd6cb6c57b416df49874c56ceb8b3b45d1cf Mon Sep 17 00:00:00 2001 From: Zbynek Slajchrt Date: Wed, 6 May 2020 11:10:06 +0200 Subject: [PATCH] Method isInternalObject removed --- .../llvm/runtime/debug/LLDBSupport.java | 4 +-- .../runtime/interop/LLVMDataEscapeNode.java | 6 +++- .../interop/LLVMInternalTruffleObject.java | 2 ++ .../interop/LLVMTypedForeignObject.java | 4 +-- .../internal/LLVMAsForeignLibrary.java | 20 +++++++++-- .../LLVMAsForeignLibraryDefaults.java | 24 +++++++++---- .../library/internal/LLVMNativeLibrary.java | 4 --- .../internal/LLVMNativeLibraryDefaults.java | 10 ------ .../pointer/ManagedPointerLibraries.java | 36 ++++--------------- .../pointer/NativePointerLibraries.java | 2 ++ 10 files changed, 53 insertions(+), 59 deletions(-) diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/debug/LLDBSupport.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/debug/LLDBSupport.java index 7875e21b18a3..ebcf1eb2b94e 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/debug/LLDBSupport.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/debug/LLDBSupport.java @@ -39,7 +39,7 @@ import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.llvm.runtime.CommonNodeFactory; import com.oracle.truffle.llvm.runtime.LLVMLanguage; -import com.oracle.truffle.llvm.runtime.library.internal.LLVMNativeLibrary; +import com.oracle.truffle.llvm.runtime.library.internal.LLVMAsForeignLibrary; import com.oracle.truffle.llvm.runtime.nodes.api.LLVMLoadNode; import com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer; import com.oracle.truffle.llvm.runtime.pointer.LLVMPointer; @@ -88,7 +88,7 @@ public static boolean pointsToObjectAccess(LLVMPointer pointer) { final LLVMManagedPointer managedPointer = LLVMManagedPointer.cast(pointer); final Object target = managedPointer.getObject(); - return LLVMNativeLibrary.getFactory().getUncached().isInternalObject(target); + return !LLVMAsForeignLibrary.getFactory().getUncached().isForeign(target); } private static boolean isByteAligned(long bits) { diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMDataEscapeNode.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMDataEscapeNode.java index 948ed053d6d8..b4678eaee2b4 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMDataEscapeNode.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMDataEscapeNode.java @@ -261,7 +261,11 @@ static TruffleObject escapingType(LLVMInteropType escapingValue, @SuppressWarnin return escapingValue; } - @Specialization(guards = "foreigns.isForeign(object)") + static boolean isPrimitiveValue(Object object) { + return object instanceof Long || object instanceof Double; + } + + @Specialization(guards = {"!isPrimitiveValue(object)", "foreigns.isForeign(object)"}) static Object escapingForeignNonPointer(Object object, @SuppressWarnings("unused") LLVMInteropType.Structured type, @CachedLibrary(limit = "3") LLVMAsForeignLibrary foreigns) { return foreigns.asForeign(object); diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMInternalTruffleObject.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMInternalTruffleObject.java index a5417d429acb..4021e592a0b4 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMInternalTruffleObject.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMInternalTruffleObject.java @@ -36,11 +36,13 @@ import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.llvm.runtime.LLVMLanguage; +import com.oracle.truffle.llvm.runtime.library.internal.LLVMAsForeignLibrary; /** * Base class to mark {@link TruffleObject} implementors that are not considered foreign. */ @ExportLibrary(InteropLibrary.class) +@ExportLibrary(LLVMAsForeignLibrary.class) public abstract class LLVMInternalTruffleObject implements TruffleObject { @ExportMessage diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMTypedForeignObject.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMTypedForeignObject.java index 1276700019c8..f7019a7f8d09 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMTypedForeignObject.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/interop/LLVMTypedForeignObject.java @@ -842,12 +842,12 @@ static boolean doGeneric(LLVMTypedForeignObject receiver, Object other) { @ExportMessage @SuppressWarnings("static-method") - boolean isForeign() { + public boolean isForeign() { return true; } @ExportMessage - Object asForeign() { + public Object asForeign() { return foreign; } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibrary.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibrary.java index 7560d52634f0..8b94fbf67e51 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibrary.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibrary.java @@ -33,9 +33,11 @@ import com.oracle.truffle.api.library.GenerateLibrary.DefaultExport; import com.oracle.truffle.api.library.Library; import com.oracle.truffle.api.library.LibraryFactory; +import com.oracle.truffle.llvm.runtime.except.LLVMException; @GenerateLibrary -@DefaultExport(LLVMAsForeignLibraryDefaults.class) +@DefaultExport(LLVMAsForeignLibraryDefaults.ArrayAsForeignLibrary.class) +@DefaultExport(LLVMAsForeignLibraryDefaults.DefaultAsForeignLibrary.class) public abstract class LLVMAsForeignLibrary extends Library { static final LibraryFactory FACTORY = LibraryFactory.resolve(LLVMAsForeignLibrary.class); @@ -44,8 +46,20 @@ public static LibraryFactory getFactory() { return FACTORY; } - public abstract boolean isForeign(Object receiver); + public boolean isForeign(@SuppressWarnings("unused") Object receiver) { + return false; + } + + public Object asForeign(@SuppressWarnings("unused") Object receiver) { + throw new NotForeignObjectException(); + } - public abstract Object asForeign(Object receiver); + public class NotForeignObjectException extends LLVMException { + private static final long serialVersionUID = 3841115158039517295L; + + public NotForeignObjectException() { + super(null); + } + } } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibraryDefaults.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibraryDefaults.java index 879e973e1b45..303ac8d0952e 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibraryDefaults.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMAsForeignLibraryDefaults.java @@ -32,16 +32,26 @@ import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; -@ExportLibrary(value = LLVMAsForeignLibrary.class, receiverType = Object.class) public class LLVMAsForeignLibraryDefaults { - @ExportMessage - static boolean isForeign(@SuppressWarnings("unused") Object receiver) { - return false; + @ExportLibrary(value = LLVMAsForeignLibrary.class, receiverType = Object.class) + static class DefaultAsForeignLibrary { + + @ExportMessage + static boolean isForeign(@SuppressWarnings("unused") Object receiver) { + return true; + } + + @ExportMessage + static Object asForeign(@SuppressWarnings("unused") Object receiver) { + return receiver; + } + } - @ExportMessage - static Object asForeign(@SuppressWarnings("unused") Object receiver) { - return null; + @ExportLibrary(value = LLVMAsForeignLibrary.class, receiverType = int[].class) + static class ArrayAsForeignLibrary { + // the inherited isForeign returns false } + } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibrary.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibrary.java index 1149176a5431..a93e2ce14aa3 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibrary.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibrary.java @@ -70,9 +70,5 @@ public long asPointer(Object receiver) throws UnsupportedMessageException { throw UnsupportedMessageException.create(); } - public boolean isInternalObject(Object receiver) { - return true; - } - public abstract LLVMNativePointer toNativePointer(Object receiver); } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibraryDefaults.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibraryDefaults.java index 8c05de0000b6..84a5a3911542 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibraryDefaults.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/library/internal/LLVMNativeLibraryDefaults.java @@ -47,11 +47,6 @@ abstract class LLVMNativeLibraryDefaults { @ExportLibrary(value = LLVMNativeLibrary.class, receiverType = Object.class) static class DefaultLibrary { - @ExportMessage - static boolean isInternalObject(@SuppressWarnings("unused") Object receiver) { - return false; - } - @ExportMessage @SuppressWarnings("unused") static class IsPointer { @@ -130,11 +125,6 @@ static LLVMNativePointer doNotNull(Object receiver, @ExportLibrary(value = LLVMNativeLibrary.class, receiverType = Long.class) static class LongLibrary { - @ExportMessage - static boolean isInternalObject(@SuppressWarnings("unused") Long receiver) { - return false; - } - @ExportMessage @SuppressWarnings("unused") static boolean isPointer(Long receiver) { diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/ManagedPointerLibraries.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/ManagedPointerLibraries.java index f354f3b8c459..557fca6790ea 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/ManagedPointerLibraries.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/ManagedPointerLibraries.java @@ -29,8 +29,6 @@ */ package com.oracle.truffle.llvm.runtime.pointer; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.interop.ArityException; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.UnsupportedMessageException; @@ -38,7 +36,6 @@ import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; -import com.oracle.truffle.llvm.runtime.interop.LLVMInternalTruffleObject; import com.oracle.truffle.llvm.runtime.library.internal.LLVMAsForeignLibrary; import com.oracle.truffle.llvm.runtime.library.internal.LLVMNativeLibrary; @@ -104,39 +101,18 @@ static LLVMNativePointer toNativePointer(LLVMPointerImpl receiver, } @ExportMessage - static class IsForeign { - - @Specialization(guards = {"isForeignTest(receiver, foreigns)"}) - static boolean isForeignObject(@SuppressWarnings("unused") LLVMPointerImpl receiver, - @SuppressWarnings("unused") @CachedLibrary(limit = "3") LLVMAsForeignLibrary foreigns) { - return true; - } - - @Specialization(guards = {"!isForeignTest(receiver, foreigns)"}) - static boolean doFallback(LLVMPointerImpl receiver, - @SuppressWarnings("unused") @CachedLibrary(limit = "3") LLVMAsForeignLibrary foreigns, - @CachedLibrary(limit = "3") LLVMNativeLibrary natives) { - return !(receiver.object instanceof LLVMInternalTruffleObject) && !LLVMPointer.isInstance(receiver.object) && !natives.isInternalObject(receiver.object); - } + static boolean isForeign(LLVMPointerImpl receiver, + @CachedLibrary(limit = "3") LLVMAsForeignLibrary foreigns) { + return isForeignTest(receiver, foreigns); } @ExportMessage - static class AsForeign { - - @Specialization(guards = {"isForeignTest(receiver, foreigns)"}) - static Object isForeignObject(LLVMPointerImpl receiver, - @CachedLibrary(limit = "3") LLVMAsForeignLibrary foreigns) { - return foreigns.asForeign(receiver.object); - } - - @Fallback - static Object doFallback(LLVMPointerImpl receiver) { - return receiver.object; - } + static Object asForeign(LLVMPointerImpl receiver, + @CachedLibrary(limit = "3") LLVMAsForeignLibrary foreigns) { + return foreigns.asForeign(receiver.object); } static boolean isForeignTest(LLVMPointerImpl receiver, LLVMAsForeignLibrary foreigns) { return receiver.getOffset() == 0 && foreigns.isForeign(receiver.object); } - } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/NativePointerLibraries.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/NativePointerLibraries.java index fd8fe23b3207..ac2576a727c2 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/NativePointerLibraries.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/pointer/NativePointerLibraries.java @@ -44,9 +44,11 @@ import com.oracle.truffle.llvm.runtime.LLVMContext; import com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor; import com.oracle.truffle.llvm.runtime.LLVMLanguage; +import com.oracle.truffle.llvm.runtime.library.internal.LLVMAsForeignLibrary; import com.oracle.truffle.llvm.runtime.library.internal.LLVMNativeLibrary; @ExportLibrary(value = LLVMNativeLibrary.class, receiverType = LLVMPointerImpl.class) +@ExportLibrary(value = LLVMAsForeignLibrary.class, receiverType = LLVMPointerImpl.class) @ExportLibrary(value = InteropLibrary.class, receiverType = LLVMPointerImpl.class) abstract class NativePointerLibraries extends CommonPointerLibraries {