diff options
Diffstat (limited to 'luni/src')
19 files changed, 125 insertions, 25 deletions
diff --git a/luni/src/main/native/NetworkUtilities.cpp b/luni/src/main/native/NetworkUtilities.cpp index 90ecd9e..ca0e122 100644 --- a/luni/src/main/native/NetworkUtilities.cpp +++ b/luni/src/main/native/NetworkUtilities.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define LOG_TAG "NetworkUtilities" + #include "NetworkUtilities.h" #include "JNIHelp.h" diff --git a/luni/src/main/native/java_io_Console.cpp b/luni/src/main/native/java_io_Console.cpp index f6c69e7..3c80c3d 100644 --- a/luni/src/main/native/java_io_Console.cpp +++ b/luni/src/main/native/java_io_Console.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "Console" + #include "JNIHelp.h" #include <errno.h> diff --git a/luni/src/main/native/java_io_File.cpp b/luni/src/main/native/java_io_File.cpp index e981f56..fa41ad2 100644 --- a/luni/src/main/native/java_io_File.cpp +++ b/luni/src/main/native/java_io_File.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "File" + #include "JNIHelp.h" #include "LocalArray.h" #include "ScopedFd.h" diff --git a/luni/src/main/native/java_io_ObjectInputStream.cpp b/luni/src/main/native/java_io_ObjectInputStream.cpp index 224603e..e88f384 100644 --- a/luni/src/main/native/java_io_ObjectInputStream.cpp +++ b/luni/src/main/native/java_io_ObjectInputStream.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "ObjectInputStream" + #include "JNIHelp.h" #include "ScopedUtfChars.h" diff --git a/luni/src/main/native/java_io_ObjectOutputStream.cpp b/luni/src/main/native/java_io_ObjectOutputStream.cpp index c499bac..c4de575 100644 --- a/luni/src/main/native/java_io_ObjectOutputStream.cpp +++ b/luni/src/main/native/java_io_ObjectOutputStream.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "ObjectOutputStream" + #include "JNIHelp.h" #include "ScopedUtfChars.h" diff --git a/luni/src/main/native/java_io_ObjectStreamClass.cpp b/luni/src/main/native/java_io_ObjectStreamClass.cpp index 666692d..395e39f 100644 --- a/luni/src/main/native/java_io_ObjectStreamClass.cpp +++ b/luni/src/main/native/java_io_ObjectStreamClass.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "ObjectStreamClass" + #include "JNIHelp.h" static jobject java_io_osc_getFieldSignature(JNIEnv* env, jclass, @@ -35,8 +37,8 @@ static jobject java_io_osc_getFieldSignature(JNIEnv* env, jclass, } jclass fieldClass = env->GetObjectClass(reflectField); - - return env->CallNonvirtualObjectMethod(reflectField, + + return env->CallNonvirtualObjectMethod(reflectField, fieldClass, mid); } @@ -56,9 +58,9 @@ static jobject java_io_osc_getMethodSignature(JNIEnv* env, jclass, if(!mid) { return NULL; } - + jclass methodClass = env->GetObjectClass(reflectMethod); - return env->CallNonvirtualObjectMethod(reflectMethod, + return env->CallNonvirtualObjectMethod(reflectMethod, methodClass, mid); } diff --git a/luni/src/main/native/java_lang_Double.cpp b/luni/src/main/native/java_lang_Double.cpp index 65576f7..2030cd6 100644 --- a/luni/src/main/native/java_lang_Double.cpp +++ b/luni/src/main/native/java_lang_Double.cpp @@ -1,9 +1,21 @@ -// -// java_lang_Double.c -// Android -// -// Copyright 2005 The Android Open Source Project -// +/* + * Copyright (C) 2005 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. + */ + +#define LOG_TAG "Double" + #include "JNIHelp.h" #include <math.h> diff --git a/luni/src/main/native/java_lang_Float.cpp b/luni/src/main/native/java_lang_Float.cpp index 08f5464..afafe72 100644 --- a/luni/src/main/native/java_lang_Float.cpp +++ b/luni/src/main/native/java_lang_Float.cpp @@ -1,9 +1,21 @@ -// -// java_lang_Float.c -// Android -// -// Copyright 2005 The Android Open Source Project -// +/* + * Copyright (C) 2005 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. + */ + +#define LOG_TAG "Float" + #include "JNIHelp.h" #include <math.h> diff --git a/luni/src/main/native/java_lang_Math.cpp b/luni/src/main/native/java_lang_Math.cpp index 7fdce6f..c549f31 100644 --- a/luni/src/main/native/java_lang_Math.cpp +++ b/luni/src/main/native/java_lang_Math.cpp @@ -1,8 +1,21 @@ /* - * Copyright 2006 The Android Open Source Project + * Copyright (C) 2006 The Android Open Source Project * - * Native functions for java.lang.Math. + * 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. */ + +#define LOG_TAG "Math" + #include "jni.h" #include "JNIHelp.h" diff --git a/luni/src/main/native/java_lang_StrictMath.cpp b/luni/src/main/native/java_lang_StrictMath.cpp index 0077d45..8c13907 100644 --- a/luni/src/main/native/java_lang_StrictMath.cpp +++ b/luni/src/main/native/java_lang_StrictMath.cpp @@ -1,8 +1,21 @@ /* - * Copyright 2006 The Android Open Source Project + * Copyright (C) 2006 The Android Open Source Project * - * Native functions for java.lang.StrictMath. + * 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. */ + +#define LOG_TAG "StrictMath" + #include "jni.h" #include "JNIHelp.h" diff --git a/luni/src/main/native/java_lang_System.cpp b/luni/src/main/native/java_lang_System.cpp index 61a784a..3b907db 100644 --- a/luni/src/main/native/java_lang_System.cpp +++ b/luni/src/main/native/java_lang_System.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define LOG_TAG "System" + #include "JNIHelp.h" #include "ScopedUtfChars.h" diff --git a/luni/src/main/native/java_net_NetworkInterface.cpp b/luni/src/main/native/java_net_NetworkInterface.cpp index 8a9675f..6a0d342 100644 --- a/luni/src/main/native/java_net_NetworkInterface.cpp +++ b/luni/src/main/native/java_net_NetworkInterface.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "NetworkInterface" + #include "JNIHelp.h" #include "jni.h" #include "NetworkUtilities.h" diff --git a/luni/src/main/native/java_util_zip_Adler32.cpp b/luni/src/main/native/java_util_zip_Adler32.cpp index d7b55be..b326225 100644 --- a/luni/src/main/native/java_util_zip_Adler32.cpp +++ b/luni/src/main/native/java_util_zip_Adler32.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "Adler32" + #include "JNIHelp.h" #include "ScopedPrimitiveArray.h" #include "jni.h" diff --git a/luni/src/main/native/java_util_zip_CRC32.cpp b/luni/src/main/native/java_util_zip_CRC32.cpp index 596f553..901f7a5 100644 --- a/luni/src/main/native/java_util_zip_CRC32.cpp +++ b/luni/src/main/native/java_util_zip_CRC32.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "CRC32" + #include "JNIHelp.h" #include "ScopedPrimitiveArray.h" #include "jni.h" diff --git a/luni/src/main/native/java_util_zip_Deflater.cpp b/luni/src/main/native/java_util_zip_Deflater.cpp index b264a6a..924cd61 100644 --- a/luni/src/main/native/java_util_zip_Deflater.cpp +++ b/luni/src/main/native/java_util_zip_Deflater.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "Deflater" + #include "ScopedPrimitiveArray.h" #include "zip.h" diff --git a/luni/src/main/native/java_util_zip_Inflater.cpp b/luni/src/main/native/java_util_zip_Inflater.cpp index 8ce9909..4fb884e 100644 --- a/luni/src/main/native/java_util_zip_Inflater.cpp +++ b/luni/src/main/native/java_util_zip_Inflater.cpp @@ -15,8 +15,11 @@ * limitations under the License. */ +#define LOG_TAG "Inflater" + #include "ScopedPrimitiveArray.h" #include "zip.h" +#include <errno.h> static struct { jfieldID inRead; @@ -56,17 +59,38 @@ static void Inflater_setInputImpl(JNIEnv* env, jobject, jbyteArray buf, jint off static jint Inflater_setFileInputImpl(JNIEnv* env, jobject, jobject javaFileDescriptor, jlong off, jint len, jlong handle) { NativeZipStream* stream = toNativeZipStream(handle); + + // We reuse the existing native buffer if it's large enough. + // TODO: benchmark. if (stream->inCap < len) { stream->setInput(env, NULL, 0, len); } else { - stream->stream.next_in = (Bytef *) &stream->input[0]; + stream->stream.next_in = reinterpret_cast<Bytef*>(&stream->input[0]); stream->stream.avail_in = len; } - // TODO: is it okay to be this sloppy about errors? + // As an Android-specific optimization, we read directly onto the native heap. + // The original code used Java to read onto the Java heap and then called setInput(byte[]). + // TODO: benchmark. int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); - lseek(fd, off, SEEK_SET); - return read(fd, &stream->input[0], len); + int rc = TEMP_FAILURE_RETRY(lseek(fd, off, SEEK_SET)); + if (rc == -1) { + jniThrowIOException(env, errno); + return 0; + } + jint totalByteCount = 0; + Bytef* dst = reinterpret_cast<Bytef*>(&stream->input[0]); + ssize_t byteCount; + while ((byteCount = TEMP_FAILURE_RETRY(read(fd, dst, len))) > 0) { + dst += byteCount; + len -= byteCount; + totalByteCount += byteCount; + } + if (byteCount == -1) { + jniThrowIOException(env, errno); + return 0; + } + return totalByteCount; } static jint Inflater_inflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int off, int len, jlong handle) { diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp index 82bc0c6..59c08ce 100644 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "OSFileSystem" + /* Values for HyFileOpen */ #define HyOpenRead 1 #define HyOpenWrite 2 diff --git a/luni/src/main/native/org_apache_harmony_luni_util_NumberConvert.cpp b/luni/src/main/native/org_apache_harmony_luni_util_NumberConvert.cpp index 1b3ea75..c0a6c31 100644 --- a/luni/src/main/native/org_apache_harmony_luni_util_NumberConvert.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_util_NumberConvert.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "NumberConvert" + #include <string.h> #include <math.h> #include <stdlib.h> diff --git a/luni/src/main/native/zip.h b/luni/src/main/native/zip.h index 6a4c201..5559a00 100644 --- a/luni/src/main/native/zip.h +++ b/luni/src/main/native/zip.h @@ -83,7 +83,7 @@ public: if (buf != NULL) { env->GetByteArrayRegion(buf, off, len, &input[0]); } - stream.next_in = (Bytef *) &input[0]; + stream.next_in = reinterpret_cast<Bytef*>(&input[0]); stream.avail_in = len; } |