Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc69cf23 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Ravenwood] Cleanup JVM workarounds" into main

parents 3e034bb8 c08c4bd0
Loading
Loading
Loading
Loading
+10 −53
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import android.content.ContentResolver;
import android.net.Uri;
import android.os.MessageQueue.OnFileDescriptorEventListener;
import android.ravenwood.annotation.RavenwoodKeepWholeClass;
import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass;
import android.ravenwood.annotation.RavenwoodReplace;
import android.ravenwood.annotation.RavenwoodThrow;
import android.system.ErrnoException;
@@ -77,8 +76,6 @@ import java.nio.ByteOrder;
 * you to close it when done with it.
 */
@RavenwoodKeepWholeClass
@RavenwoodNativeSubstitutionClass(
        "com.android.platform.test.ravenwood.nativesubstitution.ParcelFileDescriptor_host")
public class ParcelFileDescriptor implements Parcelable, Closeable {
    private static final String TAG = "ParcelFileDescriptor";

@@ -206,11 +203,11 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        }
        mWrapped = null;
        mFd = fd;
        setFdOwner(mFd);
        IoUtils.setFdOwner(mFd, this);

        mCommFd = commChannel;
        if (mCommFd != null) {
            setFdOwner(mCommFd);
            IoUtils.setFdOwner(mCommFd, this);
        }

        mGuard.open("close");
@@ -298,7 +295,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    public static @NonNull ParcelFileDescriptor wrap(@NonNull ParcelFileDescriptor pfd,
            @NonNull Handler handler, @NonNull OnCloseListener listener) throws IOException {
        final FileDescriptor original = new FileDescriptor();
        setFdInt(original, pfd.detachFd());
        original.setInt$(pfd.detachFd());
        return fromFd(original, handler, listener);
    }

@@ -363,18 +360,10 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        }
    }

    @RavenwoodReplace
    private static void closeInternal(FileDescriptor fd) {
        IoUtils.closeQuietly(fd);
    }

    private static void closeInternal$ravenwood(FileDescriptor fd) {
        try {
            Os.close(fd);
        } catch (ErrnoException ignored) {
        }
    }

    /**
     * Create a new ParcelFileDescriptor that is a dup of an existing
     * FileDescriptor.  This obeys standard POSIX semantics, where the
@@ -385,7 +374,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        try {
            final FileDescriptor fd = new FileDescriptor();
            int intfd = Os.fcntlInt(orig, (isAtLeastQ() ? F_DUPFD_CLOEXEC : F_DUPFD), 0);
            setFdInt(fd, intfd);
            fd.setInt$(intfd);
            return new ParcelFileDescriptor(fd);
        } catch (ErrnoException e) {
            throw e.rethrowAsIOException();
@@ -418,12 +407,12 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     */
    public static ParcelFileDescriptor fromFd(int fd) throws IOException {
        final FileDescriptor original = new FileDescriptor();
        setFdInt(original, fd);
        original.setInt$(fd);

        try {
            final FileDescriptor dup = new FileDescriptor();
            int intfd = Os.fcntlInt(original, (isAtLeastQ() ? F_DUPFD_CLOEXEC : F_DUPFD), 0);
            setFdInt(dup, intfd);
            dup.setInt$(intfd);
            return new ParcelFileDescriptor(dup);
        } catch (ErrnoException e) {
            throw e.rethrowAsIOException();
@@ -446,7 +435,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     */
    public static ParcelFileDescriptor adoptFd(int fd) {
        final FileDescriptor fdesc = new FileDescriptor();
        setFdInt(fdesc, fd);
        fdesc.setInt$(fd);

        return new ParcelFileDescriptor(fdesc);
    }
@@ -703,7 +692,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    @RavenwoodThrow(reason = "Os.readlink() and Os.stat()")
    public static File getFile(FileDescriptor fd) throws IOException {
        try {
            final String path = Os.readlink("/proc/self/fd/" + getFdInt(fd));
            final String path = Os.readlink("/proc/self/fd/" + fd.getInt$());
            if (OsConstants.S_ISREG(Os.stat(path).st_mode)
                    || OsConstants.S_ISCHR(Os.stat(path).st_mode)) {
                return new File(path);
@@ -783,7 +772,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
            if (mClosed) {
                throw new IllegalStateException("Already closed");
            }
            return getFdInt(mFd);
            return mFd.getInt$();
        }
    }

@@ -805,7 +794,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
            if (mClosed) {
                throw new IllegalStateException("Already closed");
            }
            int fd = acquireRawFd(mFd);
            int fd = IoUtils.acquireRawFd(mFd);
            writeCommStatusAndClose(Status.DETACHED, null);
            mClosed = true;
            mGuard.close();
@@ -1265,38 +1254,6 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        }
    }

    private static native void setFdInt$ravenwood(FileDescriptor fd, int fdInt);
    private static native int getFdInt$ravenwood(FileDescriptor fd);

    @RavenwoodReplace
    private static void setFdInt(FileDescriptor fd, int fdInt) {
        fd.setInt$(fdInt);
    }

    @RavenwoodReplace
    private static int getFdInt(FileDescriptor fd) {
        return fd.getInt$();
    }

    @RavenwoodReplace
    private void setFdOwner(FileDescriptor fd) {
        IoUtils.setFdOwner(fd, this);
    }

    private void setFdOwner$ravenwood(FileDescriptor fd) {
        // FD owners currently unsupported under Ravenwood; ignored
    }

    @RavenwoodReplace
    private int acquireRawFd(FileDescriptor fd) {
        return IoUtils.acquireRawFd(fd);
    }

    private int acquireRawFd$ravenwood(FileDescriptor fd) {
        // FD owners currently unsupported under Ravenwood; return FD directly
        return getFdInt(fd);
    }

    @RavenwoodReplace
    private static boolean isAtLeastQ() {
        return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q);
+1 −6
Original line number Diff line number Diff line
@@ -838,16 +838,11 @@ public class Process {
    /**
     * Returns true if the current process is a 64-bit runtime.
     */
    @android.ravenwood.annotation.RavenwoodReplace
    @android.ravenwood.annotation.RavenwoodKeep
    public static final boolean is64Bit() {
        return VMRuntime.getRuntime().is64Bit();
    }

    /** @hide */
    public static final boolean is64Bit$ravenwood() {
        return "amd64".equals(System.getProperty("os.arch"));
    }

    private static volatile ThreadLocal<SomeArgs> sIdentity$ravenwood;

    /** @hide */
+0 −7
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.util;

import android.compat.annotation.UnsupportedAppUsage;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

@@ -226,16 +225,10 @@ public class LruCache<K, V> {
        }
    }

    @android.ravenwood.annotation.RavenwoodReplace
    private Map.Entry<K, V> eldest() {
        return map.eldest();
    }

    private Map.Entry<K, V> eldest$ravenwood() {
        final Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
        return it.hasNext() ? it.next() : null;
    }

    /**
     * Removes the entry for {@code key} if it exists.
     *
+0 −40
Original line number Diff line number Diff line
@@ -49,81 +49,41 @@ public class ArrayUtils {

    private ArrayUtils() { /* cannot be instantiated */ }

    @android.ravenwood.annotation.RavenwoodReplace
    public static byte[] newUnpaddedByteArray(int minLen) {
        return (byte[])VMRuntime.getRuntime().newUnpaddedArray(byte.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    public static char[] newUnpaddedCharArray(int minLen) {
        return (char[])VMRuntime.getRuntime().newUnpaddedArray(char.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public static int[] newUnpaddedIntArray(int minLen) {
        return (int[])VMRuntime.getRuntime().newUnpaddedArray(int.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    public static boolean[] newUnpaddedBooleanArray(int minLen) {
        return (boolean[])VMRuntime.getRuntime().newUnpaddedArray(boolean.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    public static long[] newUnpaddedLongArray(int minLen) {
        return (long[])VMRuntime.getRuntime().newUnpaddedArray(long.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    public static float[] newUnpaddedFloatArray(int minLen) {
        return (float[])VMRuntime.getRuntime().newUnpaddedArray(float.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    public static Object[] newUnpaddedObjectArray(int minLen) {
        return (Object[])VMRuntime.getRuntime().newUnpaddedArray(Object.class, minLen);
    }

    @android.ravenwood.annotation.RavenwoodReplace
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @SuppressWarnings("unchecked")
    public static <T> T[] newUnpaddedArray(Class<T> clazz, int minLen) {
        return (T[])VMRuntime.getRuntime().newUnpaddedArray(clazz, minLen);
    }

    public static byte[] newUnpaddedByteArray$ravenwood(int minLen) {
        return new byte[minLen];
    }

    public static char[] newUnpaddedCharArray$ravenwood(int minLen) {
        return new char[minLen];
    }

    public static int[] newUnpaddedIntArray$ravenwood(int minLen) {
        return new int[minLen];
    }

    public static boolean[] newUnpaddedBooleanArray$ravenwood(int minLen) {
        return new boolean[minLen];
    }

    public static long[] newUnpaddedLongArray$ravenwood(int minLen) {
        return new long[minLen];
    }

    public static float[] newUnpaddedFloatArray$ravenwood(int minLen) {
        return new float[minLen];
    }

    public static Object[] newUnpaddedObjectArray$ravenwood(int minLen) {
        return new Object[minLen];
    }

    public static <T> T[] newUnpaddedArray$ravenwood(Class<T> clazz, int minLen) {
        return (T[]) Array.newInstance(clazz, minLen);
    }

    /**
     * Checks if the beginnings of two byte arrays are equal.
     *
+1 −1
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
 */
package android.system;

import com.android.ravenwood.RavenwoodRuntimeNative;
import com.android.ravenwood.common.JvmWorkaround;
import com.android.ravenwood.common.RavenwoodRuntimeNative;

import java.io.FileDescriptor;
import java.io.FileInputStream;
Loading