From c08c4bd0078aded45e97a68778b3ba5f53be5a9e Mon Sep 17 00:00:00 2001 From: John Wu Date: Wed, 21 Aug 2024 19:39:36 +0000 Subject: [Ravenwood] Cleanup JVM workarounds Remove JVM/ART workarounds in the framework codebase as much as possible so that we don't need to clean up a huge amount of code when we eventually switch to ART and use libcore directly. Bug: 359983716 Flag: EXEMPT host side change only Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh Change-Id: I81efeec4303dda507f5d5ad75b6d561034ce96d1 --- core/java/android/os/ParcelFileDescriptor.java | 63 +++----------- core/java/android/os/Process.java | 7 +- core/java/android/util/LruCache.java | 7 -- .../java/com/android/internal/util/ArrayUtils.java | 40 --------- .../ParcelFileDescriptor_host.java | 31 ------- .../libcore-fake/android/system/Os.java | 2 +- .../com/android/ravenwood/RavenwoodJdkPatch.java | 49 +++++++++++ .../android/ravenwood/RavenwoodRuntimeNative.java | 99 ++++++++++++++++++++++ .../ravenwood/common/RavenwoodRuntimeNative.java | 96 --------------------- .../libcore-fake/dalvik/system/VMRuntime.java | 4 +- .../libcore-fake/libcore/io/IoUtils.java | 26 ++++++ .../libcore/util/NativeAllocationRegistry.java | 2 +- ravenwood/runtime-jni/ravenwood_runtime.cpp | 2 +- ravenwood/texts/ravenwood-framework-policies.txt | 7 ++ 14 files changed, 197 insertions(+), 238 deletions(-) delete mode 100644 ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java create mode 100644 ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java create mode 100644 ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java delete mode 100644 ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java diff --git a/core/java/android/os/ParcelFileDescriptor.java b/core/java/android/os/ParcelFileDescriptor.java index 4cc057a8e0ed..e80efd2a9380 100644 --- a/core/java/android/os/ParcelFileDescriptor.java +++ b/core/java/android/os/ParcelFileDescriptor.java @@ -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); diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index db06a6ba0ef5..3b2041b0d50a 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -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 sIdentity$ravenwood; /** @hide */ diff --git a/core/java/android/util/LruCache.java b/core/java/android/util/LruCache.java index be1ec4187ddc..9845f9e7b804 100644 --- a/core/java/android/util/LruCache.java +++ b/core/java/android/util/LruCache.java @@ -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 { } } - @android.ravenwood.annotation.RavenwoodReplace private Map.Entry eldest() { return map.eldest(); } - private Map.Entry eldest$ravenwood() { - final Iterator> it = map.entrySet().iterator(); - return it.hasNext() ? it.next() : null; - } - /** * Removes the entry for {@code key} if it exists. * diff --git a/core/java/com/android/internal/util/ArrayUtils.java b/core/java/com/android/internal/util/ArrayUtils.java index 1e2cad41065d..1e965c5db7ae 100644 --- a/core/java/com/android/internal/util/ArrayUtils.java +++ b/core/java/com/android/internal/util/ArrayUtils.java @@ -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[] newUnpaddedArray(Class 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[] newUnpaddedArray$ravenwood(Class clazz, int minLen) { - return (T[]) Array.newInstance(clazz, minLen); - } - /** * Checks if the beginnings of two byte arrays are equal. * diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java deleted file mode 100644 index 5a3589dae43a..000000000000 --- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.platform.test.ravenwood.nativesubstitution; - -import com.android.ravenwood.common.JvmWorkaround; - -import java.io.FileDescriptor; - -public class ParcelFileDescriptor_host { - public static void setFdInt(FileDescriptor fd, int fdInt) { - JvmWorkaround.getInstance().setFdInt(fd, fdInt); - } - - public static int getFdInt(FileDescriptor fd) { - return JvmWorkaround.getInstance().getFdInt(fd); - } -} diff --git a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java index 7371d0a029b9..a5c0b54a8637 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java +++ b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java @@ -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; diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java new file mode 100644 index 000000000000..96aed4b3401d --- /dev/null +++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.ravenwood; + +import com.android.ravenwood.common.JvmWorkaround; + +import java.io.FileDescriptor; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Class to host APIs that exist in libcore, but not in standard JRE. + */ +public class RavenwoodJdkPatch { + /** + * Implements FileDescriptor.getInt$() + */ + public static int getInt$(FileDescriptor fd) { + return JvmWorkaround.getInstance().getFdInt(fd); + } + + /** + * Implements FileDescriptor.setInt$(int) + */ + public static void setInt$(FileDescriptor fd, int rawFd) { + JvmWorkaround.getInstance().setFdInt(fd, rawFd); + } + + /** + * Implements LinkedHashMap.eldest() + */ + public static Map.Entry eldest(LinkedHashMap map) { + final var it = map.entrySet().iterator(); + return it.hasNext() ? it.next() : null; + } +} diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java new file mode 100644 index 000000000000..0d8408c12033 --- /dev/null +++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.ravenwood; + +import android.system.ErrnoException; +import android.system.StructStat; + +import com.android.ravenwood.common.JvmWorkaround; +import com.android.ravenwood.common.RavenwoodCommonUtils; + +import java.io.FileDescriptor; + +/** + * Class to host all the JNI methods used in ravenwood runtime. + */ +public class RavenwoodRuntimeNative { + private RavenwoodRuntimeNative() { + } + + static { + RavenwoodCommonUtils.ensureOnRavenwood(); + RavenwoodCommonUtils.loadRavenwoodNativeRuntime(); + } + + public static native void applyFreeFunction(long freeFunction, long nativePtr); + + private static native long nLseek(int fd, long offset, int whence) throws ErrnoException; + + private static native int[] nPipe2(int flags) throws ErrnoException; + + private static native int nDup(int oldfd) throws ErrnoException; + + private static native int nFcntlInt(int fd, int cmd, int arg) throws ErrnoException; + + private static native StructStat nFstat(int fd) throws ErrnoException; + + public static native StructStat lstat(String path) throws ErrnoException; + + public static native StructStat stat(String path) throws ErrnoException; + + private static native int nOpen(String path, int flags, int mode) throws ErrnoException; + + public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { + return nLseek(JvmWorkaround.getInstance().getFdInt(fd), offset, whence); + } + + public static FileDescriptor[] pipe2(int flags) throws ErrnoException { + var fds = nPipe2(flags); + var ret = new FileDescriptor[] { + new FileDescriptor(), + new FileDescriptor(), + }; + JvmWorkaround.getInstance().setFdInt(ret[0], fds[0]); + JvmWorkaround.getInstance().setFdInt(ret[1], fds[1]); + + return ret; + } + + public static FileDescriptor dup(FileDescriptor fd) throws ErrnoException { + var fdInt = nDup(JvmWorkaround.getInstance().getFdInt(fd)); + + var retFd = new FileDescriptor(); + JvmWorkaround.getInstance().setFdInt(retFd, fdInt); + return retFd; + } + + public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { + var fdInt = JvmWorkaround.getInstance().getFdInt(fd); + + return nFcntlInt(fdInt, cmd, arg); + } + + public static StructStat fstat(FileDescriptor fd) throws ErrnoException { + var fdInt = JvmWorkaround.getInstance().getFdInt(fd); + + return nFstat(fdInt); + } + + public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { + int fd = nOpen(path, flags, mode); + if (fd < 0) return null; + var retFd = new FileDescriptor(); + JvmWorkaround.getInstance().setFdInt(retFd, fd); + return retFd; + } +} diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java deleted file mode 100644 index beba83391652..000000000000 --- a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.ravenwood.common; - -import android.system.ErrnoException; -import android.system.StructStat; - -import java.io.FileDescriptor; - -/** - * Class to host all the JNI methods used in ravenwood runtime. - */ -public class RavenwoodRuntimeNative { - private RavenwoodRuntimeNative() { - } - - static { - RavenwoodCommonUtils.ensureOnRavenwood(); - RavenwoodCommonUtils.loadRavenwoodNativeRuntime(); - } - - public static native void applyFreeFunction(long freeFunction, long nativePtr); - - private static native long nLseek(int fd, long offset, int whence) throws ErrnoException; - - private static native int[] nPipe2(int flags) throws ErrnoException; - - private static native int nDup(int oldfd) throws ErrnoException; - - private static native int nFcntlInt(int fd, int cmd, int arg) throws ErrnoException; - - private static native StructStat nFstat(int fd) throws ErrnoException; - - public static native StructStat lstat(String path) throws ErrnoException; - - public static native StructStat stat(String path) throws ErrnoException; - - private static native int nOpen(String path, int flags, int mode) throws ErrnoException; - - public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { - return nLseek(JvmWorkaround.getInstance().getFdInt(fd), offset, whence); - } - - public static FileDescriptor[] pipe2(int flags) throws ErrnoException { - var fds = nPipe2(flags); - var ret = new FileDescriptor[] { - new FileDescriptor(), - new FileDescriptor(), - }; - JvmWorkaround.getInstance().setFdInt(ret[0], fds[0]); - JvmWorkaround.getInstance().setFdInt(ret[1], fds[1]); - - return ret; - } - - public static FileDescriptor dup(FileDescriptor fd) throws ErrnoException { - var fdInt = nDup(JvmWorkaround.getInstance().getFdInt(fd)); - - var retFd = new FileDescriptor(); - JvmWorkaround.getInstance().setFdInt(retFd, fdInt); - return retFd; - } - - public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { - var fdInt = JvmWorkaround.getInstance().getFdInt(fd); - - return nFcntlInt(fdInt, cmd, arg); - } - - public static StructStat fstat(FileDescriptor fd) throws ErrnoException { - var fdInt = JvmWorkaround.getInstance().getFdInt(fd); - - return nFstat(fdInt); - } - - public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { - int fd = nOpen(path, flags, mode); - if (fd < 0) return null; - var retFd = new FileDescriptor(); - JvmWorkaround.getInstance().setFdInt(retFd, fd); - return retFd; - } -} diff --git a/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java b/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java index ed5a587cdccc..ba89f71dde8a 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java +++ b/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java @@ -34,11 +34,11 @@ public class VMRuntime { } public boolean is64Bit() { - return true; + return "amd64".equals(System.getProperty("os.arch")); } public static boolean is64BitAbi(String abi) { - return true; + return abi.contains("64"); } public Object newUnpaddedArray(Class componentType, int minLength) { diff --git a/ravenwood/runtime-helper-src/libcore-fake/libcore/io/IoUtils.java b/ravenwood/runtime-helper-src/libcore-fake/libcore/io/IoUtils.java index 65c285e06bf8..2bd1ae89c824 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/libcore/io/IoUtils.java +++ b/ravenwood/runtime-helper-src/libcore-fake/libcore/io/IoUtils.java @@ -16,7 +16,13 @@ package libcore.io; +import android.system.ErrnoException; +import android.system.Os; + +import com.android.ravenwood.common.JvmWorkaround; + import java.io.File; +import java.io.FileDescriptor; import java.io.IOException; import java.net.Socket; @@ -47,6 +53,13 @@ public final class IoUtils { } } + public static void closeQuietly(FileDescriptor fd) { + try { + Os.close(fd); + } catch (ErrnoException ignored) { + } + } + public static void deleteContents(File dir) throws IOException { File[] files = dir.listFiles(); if (files != null) { @@ -58,4 +71,17 @@ public final class IoUtils { } } } + + /** + * FD owners currently unsupported under Ravenwood; ignored + */ + public static void setFdOwner(FileDescriptor fd, Object owner) { + } + + /** + * FD owners currently unsupported under Ravenwood; return FD directly + */ + public static int acquireRawFd(FileDescriptor fd) { + return JvmWorkaround.getInstance().getFdInt(fd); + } } diff --git a/ravenwood/runtime-helper-src/libcore-fake/libcore/util/NativeAllocationRegistry.java b/ravenwood/runtime-helper-src/libcore-fake/libcore/util/NativeAllocationRegistry.java index 14b5a4f0c1e0..4e7dc5d6264f 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/libcore/util/NativeAllocationRegistry.java +++ b/ravenwood/runtime-helper-src/libcore-fake/libcore/util/NativeAllocationRegistry.java @@ -15,7 +15,7 @@ */ package libcore.util; -import com.android.ravenwood.common.RavenwoodRuntimeNative; +import com.android.ravenwood.RavenwoodRuntimeNative; import java.lang.ref.Cleaner; import java.lang.ref.Reference; diff --git a/ravenwood/runtime-jni/ravenwood_runtime.cpp b/ravenwood/runtime-jni/ravenwood_runtime.cpp index c8049281bc53..f5cb019f4e7e 100644 --- a/ravenwood/runtime-jni/ravenwood_runtime.cpp +++ b/ravenwood/runtime-jni/ravenwood_runtime.cpp @@ -245,7 +245,7 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) g_StructStat = findClass(env, "android/system/StructStat"); g_StructTimespecClass = findClass(env, "android/system/StructTimespec"); - jint res = jniRegisterNativeMethods(env, "com/android/ravenwood/common/RavenwoodRuntimeNative", + jint res = jniRegisterNativeMethods(env, "com/android/ravenwood/RavenwoodRuntimeNative", sMethods, NELEM(sMethods)); if (res < 0) { return res; diff --git a/ravenwood/texts/ravenwood-framework-policies.txt b/ravenwood/texts/ravenwood-framework-policies.txt index 2d49128ae292..d962c8232bf7 100644 --- a/ravenwood/texts/ravenwood-framework-policies.txt +++ b/ravenwood/texts/ravenwood-framework-policies.txt @@ -17,6 +17,13 @@ class :r keepclass rename com/.*/nano/ devicenano/ rename android/.*/nano/ devicenano/ +# Support APIs not available in standard JRE +class java.io.FileDescriptor keep + method getInt$ ()I @com.android.ravenwood.RavenwoodJdkPatch.getInt$ + method setInt$ (I)V @com.android.ravenwood.RavenwoodJdkPatch.setInt$ +class java.util.LinkedHashMap keep + method eldest ()Ljava/util/Map$Entry; @com.android.ravenwood.RavenwoodJdkPatch.eldest + # Exported to Mainline modules; cannot use annotations class com.android.internal.util.FastXmlSerializer keepclass class com.android.internal.util.FileRotator keepclass -- cgit v1.2.3-59-g8ed1b