Merge "Use @CriticalNative for writes in Parcel."
This commit is contained in:
committed by
Android (Google) Code Review
commit
3924cd27f1
@@ -298,14 +298,15 @@ public final class Parcel {
|
||||
|
||||
private static native void nativeWriteByteArray(long nativePtr, byte[] b, int offset, int len);
|
||||
private static native void nativeWriteBlob(long nativePtr, byte[] b, int offset, int len);
|
||||
@FastNative
|
||||
private static native void nativeWriteInt(long nativePtr, int val);
|
||||
@FastNative
|
||||
private static native void nativeWriteLong(long nativePtr, long val);
|
||||
@FastNative
|
||||
private static native void nativeWriteFloat(long nativePtr, float val);
|
||||
@FastNative
|
||||
private static native void nativeWriteDouble(long nativePtr, double val);
|
||||
@CriticalNative
|
||||
private static native int nativeWriteInt(long nativePtr, int val);
|
||||
@CriticalNative
|
||||
private static native int nativeWriteLong(long nativePtr, long val);
|
||||
@CriticalNative
|
||||
private static native int nativeWriteFloat(long nativePtr, float val);
|
||||
@CriticalNative
|
||||
private static native int nativeWriteDouble(long nativePtr, double val);
|
||||
private static native void nativeSignalExceptionForError(int error);
|
||||
@FastNative
|
||||
private static native void nativeWriteString8(long nativePtr, String val);
|
||||
@FastNative
|
||||
@@ -734,12 +735,20 @@ public final class Parcel {
|
||||
nativeWriteBlob(mNativePtr, b, offset, len);
|
||||
}
|
||||
|
||||
// The OK status from system/core/libutils/include/utils/Errors.h .
|
||||
// We shall pass all other error codes back to native for throwing exceptions. The error
|
||||
// check is done in Java to allow using @CriticalNative calls for the success path.
|
||||
private static final int OK = 0;
|
||||
|
||||
/**
|
||||
* Write an integer value into the parcel at the current dataPosition(),
|
||||
* growing dataCapacity() if needed.
|
||||
*/
|
||||
public final void writeInt(int val) {
|
||||
nativeWriteInt(mNativePtr, val);
|
||||
int err = nativeWriteInt(mNativePtr, val);
|
||||
if (err != OK) {
|
||||
nativeSignalExceptionForError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -747,7 +756,10 @@ public final class Parcel {
|
||||
* growing dataCapacity() if needed.
|
||||
*/
|
||||
public final void writeLong(long val) {
|
||||
nativeWriteLong(mNativePtr, val);
|
||||
int err = nativeWriteLong(mNativePtr, val);
|
||||
if (err != OK) {
|
||||
nativeSignalExceptionForError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -755,7 +767,10 @@ public final class Parcel {
|
||||
* dataPosition(), growing dataCapacity() if needed.
|
||||
*/
|
||||
public final void writeFloat(float val) {
|
||||
nativeWriteFloat(mNativePtr, val);
|
||||
int err = nativeWriteFloat(mNativePtr, val);
|
||||
if (err != OK) {
|
||||
nativeSignalExceptionForError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -763,7 +778,10 @@ public final class Parcel {
|
||||
* current dataPosition(), growing dataCapacity() if needed.
|
||||
*/
|
||||
public final void writeDouble(double val) {
|
||||
nativeWriteDouble(mNativePtr, val);
|
||||
int err = nativeWriteDouble(mNativePtr, val);
|
||||
if (err != OK) {
|
||||
nativeSignalExceptionForError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -230,47 +230,28 @@ static void android_os_Parcel_writeBlob(JNIEnv* env, jclass clazz, jlong nativeP
|
||||
blob.release();
|
||||
}
|
||||
|
||||
static void android_os_Parcel_writeInt(JNIEnv* env, jclass clazz, jlong nativePtr, jint val) {
|
||||
static int android_os_Parcel_writeInt(jlong nativePtr, jint val) {
|
||||
Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
|
||||
if (parcel != NULL) {
|
||||
const status_t err = parcel->writeInt32(val);
|
||||
if (err != NO_ERROR) {
|
||||
signalExceptionForError(env, clazz, err);
|
||||
}
|
||||
}
|
||||
return (parcel != NULL) ? parcel->writeInt32(val) : OK;
|
||||
}
|
||||
|
||||
static void android_os_Parcel_writeLong(JNIEnv* env, jclass clazz, jlong nativePtr, jlong val)
|
||||
{
|
||||
static int android_os_Parcel_writeLong(jlong nativePtr, jlong val) {
|
||||
Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
|
||||
if (parcel != NULL) {
|
||||
const status_t err = parcel->writeInt64(val);
|
||||
if (err != NO_ERROR) {
|
||||
signalExceptionForError(env, clazz, err);
|
||||
}
|
||||
}
|
||||
return (parcel != NULL) ? parcel->writeInt64(val) : OK;
|
||||
}
|
||||
|
||||
static void android_os_Parcel_writeFloat(JNIEnv* env, jclass clazz, jlong nativePtr, jfloat val)
|
||||
{
|
||||
static int android_os_Parcel_writeFloat(jlong nativePtr, jfloat val) {
|
||||
Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
|
||||
if (parcel != NULL) {
|
||||
const status_t err = parcel->writeFloat(val);
|
||||
if (err != NO_ERROR) {
|
||||
signalExceptionForError(env, clazz, err);
|
||||
}
|
||||
}
|
||||
return (parcel != NULL) ? parcel->writeFloat(val) : OK;
|
||||
}
|
||||
|
||||
static void android_os_Parcel_writeDouble(JNIEnv* env, jclass clazz, jlong nativePtr, jdouble val)
|
||||
{
|
||||
static int android_os_Parcel_writeDouble(jlong nativePtr, jdouble val) {
|
||||
Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
|
||||
if (parcel != NULL) {
|
||||
const status_t err = parcel->writeDouble(val);
|
||||
if (err != NO_ERROR) {
|
||||
signalExceptionForError(env, clazz, err);
|
||||
}
|
||||
}
|
||||
return (parcel != NULL) ? parcel->writeDouble(val) : OK;
|
||||
}
|
||||
|
||||
static void android_os_Parcel_nativeSignalExceptionForError(JNIEnv* env, jclass clazz, jint err) {
|
||||
signalExceptionForError(env, clazz, err);
|
||||
}
|
||||
|
||||
static void android_os_Parcel_writeString8(JNIEnv* env, jclass clazz, jlong nativePtr, jstring val)
|
||||
@@ -752,14 +733,15 @@ static const JNINativeMethod gParcelMethods[] = {
|
||||
|
||||
{"nativeWriteByteArray", "(J[BII)V", (void*)android_os_Parcel_writeByteArray},
|
||||
{"nativeWriteBlob", "(J[BII)V", (void*)android_os_Parcel_writeBlob},
|
||||
// @FastNative
|
||||
{"nativeWriteInt", "(JI)V", (void*)android_os_Parcel_writeInt},
|
||||
// @FastNative
|
||||
{"nativeWriteLong", "(JJ)V", (void*)android_os_Parcel_writeLong},
|
||||
// @FastNative
|
||||
{"nativeWriteFloat", "(JF)V", (void*)android_os_Parcel_writeFloat},
|
||||
// @FastNative
|
||||
{"nativeWriteDouble", "(JD)V", (void*)android_os_Parcel_writeDouble},
|
||||
// @CriticalNative
|
||||
{"nativeWriteInt", "(JI)I", (void*)android_os_Parcel_writeInt},
|
||||
// @CriticalNative
|
||||
{"nativeWriteLong", "(JJ)I", (void*)android_os_Parcel_writeLong},
|
||||
// @CriticalNative
|
||||
{"nativeWriteFloat", "(JF)I", (void*)android_os_Parcel_writeFloat},
|
||||
// @CriticalNative
|
||||
{"nativeWriteDouble", "(JD)I", (void*)android_os_Parcel_writeDouble},
|
||||
{"nativeSignalExceptionForError", "(I)V", (void*)android_os_Parcel_nativeSignalExceptionForError},
|
||||
// @FastNative
|
||||
{"nativeWriteString8", "(JLjava/lang/String;)V", (void*)android_os_Parcel_writeString8},
|
||||
// @FastNative
|
||||
|
||||
Reference in New Issue
Block a user