summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-08-23 20:10:32 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-08-23 20:10:32 +0000
commitfc69cf23bbbe2996e20b10f9947a8aee71b5b7fd (patch)
treed1bde3b7ce7eb1c29eae9bee1e60dbb2c79e4ee2
parent3e034bb85c4f2d08362018899f6e6e5d6551cdea (diff)
parentc08c4bd0078aded45e97a68778b3ba5f53be5a9e (diff)
Merge "[Ravenwood] Cleanup JVM workarounds" into main
-rw-r--r--core/java/android/os/ParcelFileDescriptor.java63
-rw-r--r--core/java/android/os/Process.java7
-rw-r--r--core/java/android/util/LruCache.java7
-rw-r--r--core/java/com/android/internal/util/ArrayUtils.java40
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java2
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java (renamed from ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java)32
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java (renamed from ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java)5
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java4
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/libcore/io/IoUtils.java26
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/libcore/util/NativeAllocationRegistry.java2
-rw-r--r--ravenwood/runtime-jni/ravenwood_runtime.cpp2
-rw-r--r--ravenwood/texts/ravenwood-framework-policies.txt7
12 files changed, 78 insertions, 119 deletions
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<SomeArgs> 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<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.
*
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> 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.
*
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/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java
index 5a3589dae43a..96aed4b3401d 100644
--- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java
+++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodJdkPatch.java
@@ -13,19 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.android.platform.test.ravenwood.nativesubstitution;
+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);
+ }
-public class ParcelFileDescriptor_host {
- public static void setFdInt(FileDescriptor fd, int fdInt) {
- JvmWorkaround.getInstance().setFdInt(fd, fdInt);
+ /**
+ * Implements FileDescriptor.setInt$(int)
+ */
+ public static void setInt$(FileDescriptor fd, int rawFd) {
+ JvmWorkaround.getInstance().setFdInt(fd, rawFd);
}
- public static int getFdInt(FileDescriptor fd) {
- return JvmWorkaround.getInstance().getFdInt(fd);
+ /**
+ * Implements LinkedHashMap.eldest()
+ */
+ public static <K, V> Map.Entry<K, V> eldest(LinkedHashMap<K, V> 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/common/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java
index beba83391652..0d8408c12033 100644
--- a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
+++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java
@@ -13,11 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.ravenwood.common;
+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;
/**
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