diff options
author | Elliott Hughes <enh@google.com> | 2010-07-22 18:10:24 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-07-22 18:10:24 -0700 |
commit | 034db7d210969f6e516d347810695633d063eb4b (patch) | |
tree | e37934195dea96e62d8cbb013e9fb3df7568637b /luni/src/main/native | |
parent | 3b0a5b910110625c50dae6baa94d9adaf58ed46e (diff) | |
download | libcore-034db7d210969f6e516d347810695633d063eb4b.zip libcore-034db7d210969f6e516d347810695633d063eb4b.tar.gz libcore-034db7d210969f6e516d347810695633d063eb4b.tar.bz2 |
Remove more of our C-style casts, fix more of our native method names.
Change-Id: I08d7915e22faf091489171240d2f9bf8b3acecca
Diffstat (limited to 'luni/src/main/native')
-rw-r--r-- | luni/src/main/native/NativeBreakIterator.cpp | 60 | ||||
-rw-r--r-- | luni/src/main/native/NativeCollation.cpp | 80 | ||||
-rw-r--r-- | luni/src/main/native/NativeDecimalFormat.cpp | 70 | ||||
-rw-r--r-- | luni/src/main/native/java_io_Console.cpp | 8 | ||||
-rw-r--r-- | luni/src/main/native/java_lang_Math.cpp | 158 | ||||
-rw-r--r-- | luni/src/main/native/java_lang_ProcessManager.cpp | 20 | ||||
-rw-r--r-- | luni/src/main/native/java_net_NetworkInterface.cpp | 28 | ||||
-rw-r--r-- | luni/src/main/native/java_util_regex_Matcher.cpp | 48 | ||||
-rw-r--r-- | luni/src/main/native/java_util_regex_Pattern.cpp | 8 | ||||
-rw-r--r-- | luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp | 531 |
10 files changed, 379 insertions, 632 deletions
diff --git a/luni/src/main/native/NativeBreakIterator.cpp b/luni/src/main/native/NativeBreakIterator.cpp index 89ccbc6..cd4407f 100644 --- a/luni/src/main/native/NativeBreakIterator.cpp +++ b/luni/src/main/native/NativeBreakIterator.cpp @@ -35,19 +35,19 @@ static jint getIterator(JNIEnv* env, jstring locale, UBreakIteratorType type) { return reinterpret_cast<uintptr_t>(it); } -static jint getCharacterInstanceImpl(JNIEnv* env, jclass, jstring locale) { +static jint NativeBreakIterator_getCharacterInstanceImpl(JNIEnv* env, jclass, jstring locale) { return getIterator(env, locale, UBRK_CHARACTER); } -static jint getLineInstanceImpl(JNIEnv* env, jclass, jstring locale) { +static jint NativeBreakIterator_getLineInstanceImpl(JNIEnv* env, jclass, jstring locale) { return getIterator(env, locale, UBRK_LINE); } -static jint getSentenceInstanceImpl(JNIEnv* env, jclass, jstring locale) { +static jint NativeBreakIterator_getSentenceInstanceImpl(JNIEnv* env, jclass, jstring locale) { return getIterator(env, locale, UBRK_SENTENCE); } -static jint getWordInstanceImpl(JNIEnv* env, jclass, jstring locale) { +static jint NativeBreakIterator_getWordInstanceImpl(JNIEnv* env, jclass, jstring locale) { return getIterator(env, locale, UBRK_WORD); } @@ -55,11 +55,11 @@ static UBreakIterator* breakIterator(jint address) { return reinterpret_cast<UBreakIterator*>(static_cast<uintptr_t>(address)); } -static void closeBreakIteratorImpl(JNIEnv*, jclass, jint address) { +static void NativeBreakIterator_closeBreakIteratorImpl(JNIEnv*, jclass, jint address) { ubrk_close(breakIterator(address)); } -static jint cloneImpl(JNIEnv* env, jclass, jint address) { +static jint NativeBreakIterator_cloneImpl(JNIEnv* env, jclass, jint address) { UErrorCode status = U_ZERO_ERROR; jint bufferSize = U_BRK_SAFECLONE_BUFFERSIZE; UBreakIterator* it = ubrk_safeClone(breakIterator(address), NULL, &bufferSize, &status); @@ -67,7 +67,7 @@ static jint cloneImpl(JNIEnv* env, jclass, jint address) { return reinterpret_cast<uintptr_t>(it); } -static void setTextImpl(JNIEnv* env, jclass, jint address, jstring javaText) { +static void NativeBreakIterator_setTextImpl(JNIEnv* env, jclass, jint address, jstring javaText) { ScopedJavaUnicodeString text(env, javaText); UnicodeString& s(text.unicodeString()); UErrorCode status = U_ZERO_ERROR; @@ -75,11 +75,11 @@ static void setTextImpl(JNIEnv* env, jclass, jint address, jstring javaText) { icu4jni_error(env, status); } -static jboolean isBoundaryImpl(JNIEnv*, jclass, jint address, jint offset) { +static jboolean NativeBreakIterator_isBoundaryImpl(JNIEnv*, jclass, jint address, jint offset) { return ubrk_isBoundary(breakIterator(address), offset); } -static jint nextImpl(JNIEnv*, jclass, jint address, jint n) { +static jint NativeBreakIterator_nextImpl(JNIEnv*, jclass, jint address, jint n) { UBreakIterator* bi = breakIterator(address); if (n < 0) { while (n++ < -1) { @@ -97,46 +97,46 @@ static jint nextImpl(JNIEnv*, jclass, jint address, jint n) { return -1; } -static jint precedingImpl(JNIEnv*, jclass, jint address, jint offset) { +static jint NativeBreakIterator_precedingImpl(JNIEnv*, jclass, jint address, jint offset) { return ubrk_preceding(breakIterator(address), offset); } -static jint firstImpl(JNIEnv*, jclass, jint address) { +static jint NativeBreakIterator_firstImpl(JNIEnv*, jclass, jint address) { return ubrk_first(breakIterator(address)); } -static jint followingImpl(JNIEnv*, jclass, jint address, jint offset) { +static jint NativeBreakIterator_followingImpl(JNIEnv*, jclass, jint address, jint offset) { return ubrk_following(breakIterator(address), offset); } -static jint currentImpl(JNIEnv*, jclass, jint address) { +static jint NativeBreakIterator_currentImpl(JNIEnv*, jclass, jint address) { return ubrk_current(breakIterator(address)); } -static jint previousImpl(JNIEnv*, jclass, jint address) { +static jint NativeBreakIterator_previousImpl(JNIEnv*, jclass, jint address) { return ubrk_previous(breakIterator(address)); } -static jint lastImpl(JNIEnv*, jclass, jint address) { +static jint NativeBreakIterator_lastImpl(JNIEnv*, jclass, jint address) { return ubrk_last(breakIterator(address)); } static JNINativeMethod gMethods[] = { - { "cloneImpl", "(I)I", (void*) cloneImpl }, - { "closeBreakIteratorImpl", "(I)V", (void*) closeBreakIteratorImpl }, - { "currentImpl", "(I)I", (void*) currentImpl }, - { "firstImpl", "(I)I", (void*) firstImpl }, - { "followingImpl", "(II)I", (void*) followingImpl }, - { "getCharacterInstanceImpl", "(Ljava/lang/String;)I", (void*) getCharacterInstanceImpl }, - { "getLineInstanceImpl", "(Ljava/lang/String;)I", (void*) getLineInstanceImpl }, - { "getSentenceInstanceImpl", "(Ljava/lang/String;)I", (void*) getSentenceInstanceImpl }, - { "getWordInstanceImpl", "(Ljava/lang/String;)I", (void*) getWordInstanceImpl }, - { "isBoundaryImpl", "(II)Z", (void*) isBoundaryImpl }, - { "lastImpl", "(I)I", (void*) lastImpl }, - { "nextImpl", "(II)I", (void*) nextImpl }, - { "precedingImpl", "(II)I", (void*) precedingImpl }, - { "previousImpl", "(I)I", (void*) previousImpl }, - { "setTextImpl", "(ILjava/lang/String;)V", (void*) setTextImpl }, + { "cloneImpl", "(I)I", (void*) NativeBreakIterator_cloneImpl }, + { "closeBreakIteratorImpl", "(I)V", (void*) NativeBreakIterator_closeBreakIteratorImpl }, + { "currentImpl", "(I)I", (void*) NativeBreakIterator_currentImpl }, + { "firstImpl", "(I)I", (void*) NativeBreakIterator_firstImpl }, + { "followingImpl", "(II)I", (void*) NativeBreakIterator_followingImpl }, + { "getCharacterInstanceImpl", "(Ljava/lang/String;)I", (void*) NativeBreakIterator_getCharacterInstanceImpl }, + { "getLineInstanceImpl", "(Ljava/lang/String;)I", (void*) NativeBreakIterator_getLineInstanceImpl }, + { "getSentenceInstanceImpl", "(Ljava/lang/String;)I", (void*) NativeBreakIterator_getSentenceInstanceImpl }, + { "getWordInstanceImpl", "(Ljava/lang/String;)I", (void*) NativeBreakIterator_getWordInstanceImpl }, + { "isBoundaryImpl", "(II)Z", (void*) NativeBreakIterator_isBoundaryImpl }, + { "lastImpl", "(I)I", (void*) NativeBreakIterator_lastImpl }, + { "nextImpl", "(II)I", (void*) NativeBreakIterator_nextImpl }, + { "precedingImpl", "(II)I", (void*) NativeBreakIterator_precedingImpl }, + { "previousImpl", "(I)I", (void*) NativeBreakIterator_previousImpl }, + { "setTextImpl", "(ILjava/lang/String;)V", (void*) NativeBreakIterator_setTextImpl }, }; int register_com_ibm_icu4jni_text_NativeBreakIterator(JNIEnv* env) { return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeBreakIterator", diff --git a/luni/src/main/native/NativeCollation.cpp b/luni/src/main/native/NativeCollation.cpp index ed2a0e5..868a88f 100644 --- a/luni/src/main/native/NativeCollation.cpp +++ b/luni/src/main/native/NativeCollation.cpp @@ -26,15 +26,15 @@ static UCollationElements* toCollationElements(jint address) { return reinterpret_cast<UCollationElements*>(static_cast<uintptr_t>(address)); } -static void closeCollator(JNIEnv*, jclass, jint address) { +static void NativeCollation_closeCollator(JNIEnv*, jclass, jint address) { ucol_close(toCollator(address)); } -static void closeElements(JNIEnv*, jclass, jint address) { +static void NativeCollation_closeElements(JNIEnv*, jclass, jint address) { ucol_closeElements(toCollationElements(address)); } -static jint compare(JNIEnv* env, jclass, jint address, jstring lhs0, jstring rhs0) { +static jint NativeCollation_compare(JNIEnv* env, jclass, jint address, jstring lhs0, jstring rhs0) { ScopedJavaUnicodeString lhs(env, lhs0); ScopedJavaUnicodeString rhs(env, rhs0); return ucol_strcoll(toCollator(address), @@ -42,14 +42,14 @@ static jint compare(JNIEnv* env, jclass, jint address, jstring lhs0, jstring rhs rhs.unicodeString().getBuffer(), rhs.unicodeString().length()); } -static jint getAttribute(JNIEnv* env, jclass, jint address, jint type) { +static jint NativeCollation_getAttribute(JNIEnv* env, jclass, jint address, jint type) { UErrorCode status = U_ZERO_ERROR; jint result = ucol_getAttribute(toCollator(address), (UColAttribute) type, &status); icu4jni_error(env, status); return result; } -static jint getCollationElementIterator(JNIEnv* env, jclass, jint address, jstring source0) { +static jint NativeCollation_getCollationElementIterator(JNIEnv* env, jclass, jint address, jstring source0) { ScopedJavaUnicodeString source(env, source0); UErrorCode status = U_ZERO_ERROR; UCollationElements* result = ucol_openElements(toCollator(address), @@ -58,34 +58,34 @@ static jint getCollationElementIterator(JNIEnv* env, jclass, jint address, jstri return static_cast<jint>(reinterpret_cast<uintptr_t>(result)); } -static jint getMaxExpansion(JNIEnv*, jclass, jint address, jint order) { +static jint NativeCollation_getMaxExpansion(JNIEnv*, jclass, jint address, jint order) { return ucol_getMaxExpansion(toCollationElements(address), order); } -static jint getNormalization(JNIEnv* env, jclass, jint address) { +static jint NativeCollation_getNormalization(JNIEnv* env, jclass, jint address) { UErrorCode status = U_ZERO_ERROR; jint result = ucol_getAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, &status); icu4jni_error(env, status); return result; } -static void setNormalization(JNIEnv* env, jclass, jint address, jint mode) { +static void NativeCollation_setNormalization(JNIEnv* env, jclass, jint address, jint mode) { UErrorCode status = U_ZERO_ERROR; ucol_setAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, UColAttributeValue(mode), &status); icu4jni_error(env, status); } -static jint getOffset(JNIEnv*, jclass, jint address) { +static jint NativeCollation_getOffset(JNIEnv*, jclass, jint address) { return ucol_getOffset(toCollationElements(address)); } -static jstring getRules(JNIEnv* env, jclass, jint address) { +static jstring NativeCollation_getRules(JNIEnv* env, jclass, jint address) { int32_t length = 0; const UChar* rules = ucol_getRules(toCollator(address), &length); return env->NewString(rules, length); } -static jbyteArray getSortKey(JNIEnv* env, jclass, jint address, jstring source0) { +static jbyteArray NativeCollation_getSortKey(JNIEnv* env, jclass, jint address, jstring source0) { ScopedJavaUnicodeString source(env, source0); const UCollator* collator = toCollator(address); uint8_t byteArray[UCOL_MAX_BUFFER * 2]; @@ -108,14 +108,14 @@ static jbyteArray getSortKey(JNIEnv* env, jclass, jint address, jstring source0) return result; } -static jint next(JNIEnv* env, jclass, jint address) { +static jint NativeCollation_next(JNIEnv* env, jclass, jint address) { UErrorCode status = U_ZERO_ERROR; jint result = ucol_next(toCollationElements(address), &status); icu4jni_error(env, status); return result; } -static jint openCollator(JNIEnv* env, jclass, jstring localeName) { +static jint NativeCollation_openCollator(JNIEnv* env, jclass, jstring localeName) { ScopedUtfChars localeChars(env, localeName); if (localeChars.c_str() == NULL) { return 0; @@ -126,7 +126,7 @@ static jint openCollator(JNIEnv* env, jclass, jstring localeName) { return static_cast<jint>(reinterpret_cast<uintptr_t>(c)); } -static jint openCollatorFromRules(JNIEnv* env, jclass, jstring rules0, jint mode, jint strength) { +static jint NativeCollation_openCollatorFromRules(JNIEnv* env, jclass, jstring rules0, jint mode, jint strength) { ScopedJavaUnicodeString rules(env, rules0); UErrorCode status = U_ZERO_ERROR; UCollator* c = ucol_openRules(rules.unicodeString().getBuffer(), rules.unicodeString().length(), @@ -135,18 +135,18 @@ static jint openCollatorFromRules(JNIEnv* env, jclass, jstring rules0, jint mode return static_cast<jint>(reinterpret_cast<uintptr_t>(c)); } -static jint previous(JNIEnv* env, jclass, jint address) { +static jint NativeCollation_previous(JNIEnv* env, jclass, jint address) { UErrorCode status = U_ZERO_ERROR; jint result = ucol_previous(toCollationElements(address), &status); icu4jni_error(env, status); return result; } -static void reset(JNIEnv*, jclass, jint address) { +static void NativeCollation_reset(JNIEnv*, jclass, jint address) { ucol_reset(toCollationElements(address)); } -static jint safeClone(JNIEnv* env, jclass, jint address) { +static jint NativeCollation_safeClone(JNIEnv* env, jclass, jint address) { UErrorCode status = U_ZERO_ERROR; jint bufferSize = U_COL_SAFECLONE_BUFFERSIZE; UCollator* c = ucol_safeClone(toCollator(address), NULL, &bufferSize, &status); @@ -154,19 +154,19 @@ static jint safeClone(JNIEnv* env, jclass, jint address) { return static_cast<jint>(reinterpret_cast<uintptr_t>(c)); } -static void setAttribute(JNIEnv* env, jclass, jint address, jint type, jint value) { +static void NativeCollation_setAttribute(JNIEnv* env, jclass, jint address, jint type, jint value) { UErrorCode status = U_ZERO_ERROR; ucol_setAttribute(toCollator(address), (UColAttribute)type, (UColAttributeValue)value, &status); icu4jni_error(env, status); } -static void setOffset(JNIEnv* env, jclass, jint address, jint offset) { +static void NativeCollation_setOffset(JNIEnv* env, jclass, jint address, jint offset) { UErrorCode status = U_ZERO_ERROR; ucol_setOffset(toCollationElements(address), offset, &status); icu4jni_error(env, status); } -static void setText(JNIEnv* env, jclass, jint address, jstring source0) { +static void NativeCollation_setText(JNIEnv* env, jclass, jint address, jstring source0) { ScopedJavaUnicodeString source(env, source0); UErrorCode status = U_ZERO_ERROR; ucol_setText(toCollationElements(address), @@ -175,26 +175,26 @@ static void setText(JNIEnv* env, jclass, jint address, jstring source0) { } static JNINativeMethod gMethods[] = { - { "openCollator", "(Ljava/lang/String;)I", (void*) openCollator }, - { "openCollatorFromRules", "(Ljava/lang/String;II)I", (void*) openCollatorFromRules }, - { "closeCollator", "(I)V", (void*) closeCollator }, - { "compare", "(ILjava/lang/String;Ljava/lang/String;)I", (void*) compare }, - { "getNormalization", "(I)I", (void*) getNormalization }, - { "setNormalization", "(II)V", (void*) setNormalization }, - { "getRules", "(I)Ljava/lang/String;", (void*) getRules }, - { "getSortKey", "(ILjava/lang/String;)[B", (void*) getSortKey }, - { "setAttribute", "(III)V", (void*) setAttribute }, - { "getAttribute", "(II)I", (void*) getAttribute }, - { "safeClone", "(I)I", (void*) safeClone }, - { "getCollationElementIterator", "(ILjava/lang/String;)I", (void*) getCollationElementIterator }, - { "closeElements", "(I)V", (void*) closeElements }, - { "reset", "(I)V", (void*) reset }, - { "next", "(I)I", (void*) next }, - { "previous", "(I)I", (void*) previous }, - { "getMaxExpansion", "(II)I", (void*) getMaxExpansion }, - { "setText", "(ILjava/lang/String;)V", (void*) setText }, - { "getOffset", "(I)I", (void*) getOffset }, - { "setOffset", "(II)V", (void*) setOffset } + { "closeCollator", "(I)V", (void*) NativeCollation_closeCollator }, + { "closeElements", "(I)V", (void*) NativeCollation_closeElements }, + { "compare", "(ILjava/lang/String;Ljava/lang/String;)I", (void*) NativeCollation_compare }, + { "getAttribute", "(II)I", (void*) NativeCollation_getAttribute }, + { "getCollationElementIterator", "(ILjava/lang/String;)I", (void*) NativeCollation_getCollationElementIterator }, + { "getMaxExpansion", "(II)I", (void*) NativeCollation_getMaxExpansion }, + { "getNormalization", "(I)I", (void*) NativeCollation_getNormalization }, + { "getOffset", "(I)I", (void*) NativeCollation_getOffset }, + { "getRules", "(I)Ljava/lang/String;", (void*) NativeCollation_getRules }, + { "getSortKey", "(ILjava/lang/String;)[B", (void*) NativeCollation_getSortKey }, + { "next", "(I)I", (void*) NativeCollation_next }, + { "openCollator", "(Ljava/lang/String;)I", (void*) NativeCollation_openCollator }, + { "openCollatorFromRules", "(Ljava/lang/String;II)I", (void*) NativeCollation_openCollatorFromRules }, + { "previous", "(I)I", (void*) NativeCollation_previous }, + { "reset", "(I)V", (void*) NativeCollation_reset }, + { "safeClone", "(I)I", (void*) NativeCollation_safeClone }, + { "setAttribute", "(III)V", (void*) NativeCollation_setAttribute }, + { "setNormalization", "(II)V", (void*) NativeCollation_setNormalization }, + { "setOffset", "(II)V", (void*) NativeCollation_setOffset }, + { "setText", "(ILjava/lang/String;)V", (void*) NativeCollation_setText }, }; int register_com_ibm_icu4jni_text_NativeCollator(JNIEnv* env) { return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeCollation", diff --git a/luni/src/main/native/NativeDecimalFormat.cpp b/luni/src/main/native/NativeDecimalFormat.cpp index b068a45..4a7b821 100644 --- a/luni/src/main/native/NativeDecimalFormat.cpp +++ b/luni/src/main/native/NativeDecimalFormat.cpp @@ -72,7 +72,7 @@ static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env, return result; } -static void setDecimalFormatSymbols(JNIEnv* env, jclass, jint addr, +static void NativeDecimalFormat_setDecimalFormatSymbols(JNIEnv* env, jclass, jint addr, jstring currencySymbol, jchar decimalSeparator, jchar digit, jchar groupingSeparator, jstring infinity, jstring internationalCurrencySymbol, jchar minusSign, @@ -86,7 +86,7 @@ static void setDecimalFormatSymbols(JNIEnv* env, jclass, jint addr, toDecimalFormat(addr)->adoptDecimalFormatSymbols(symbols); } -static jint openDecimalFormatImpl(JNIEnv* env, jclass, jstring pattern0, +static jint NativeDecimalFormat_open(JNIEnv* env, jclass, jstring pattern0, jstring currencySymbol, jchar decimalSeparator, jchar digit, jchar groupingSeparator, jstring infinity, jstring internationalCurrencySymbol, jchar minusSign, @@ -112,17 +112,17 @@ static jint openDecimalFormatImpl(JNIEnv* env, jclass, jstring pattern0, return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt)); } -static void closeDecimalFormatImpl(JNIEnv*, jclass, jint addr) { +static void NativeDecimalFormat_close(JNIEnv*, jclass, jint addr) { delete toDecimalFormat(addr); } -static void setRoundingMode(JNIEnv*, jclass, jint addr, jint mode, jdouble increment) { +static void NativeDecimalFormat_setRoundingMode(JNIEnv*, jclass, jint addr, jint mode, jdouble increment) { DecimalFormat* fmt = toDecimalFormat(addr); fmt->setRoundingMode(static_cast<DecimalFormat::ERoundingMode>(mode)); fmt->setRoundingIncrement(increment); } -static void setSymbol(JNIEnv* env, jclass, jint addr, jint javaSymbol, jstring javaValue) { +static void NativeDecimalFormat_setSymbol(JNIEnv* env, jclass, jint addr, jint javaSymbol, jstring javaValue) { ScopedJavaUnicodeString value(env, javaValue); UnicodeString& s(value.unicodeString()); UErrorCode status = U_ZERO_ERROR; @@ -131,17 +131,17 @@ static void setSymbol(JNIEnv* env, jclass, jint addr, jint javaSymbol, jstring j icu4jni_error(env, status); } -static void setAttribute(JNIEnv*, jclass, jint addr, jint javaAttr, jint value) { +static void NativeDecimalFormat_setAttribute(JNIEnv*, jclass, jint addr, jint javaAttr, jint value) { UNumberFormatAttribute attr = static_cast<UNumberFormatAttribute>(javaAttr); unum_setAttribute(toUNumberFormat(addr), attr, value); } -static jint getAttribute(JNIEnv*, jclass, jint addr, jint javaAttr) { +static jint NativeDecimalFormat_getAttribute(JNIEnv*, jclass, jint addr, jint javaAttr) { UNumberFormatAttribute attr = static_cast<UNumberFormatAttribute>(javaAttr); return unum_getAttribute(toUNumberFormat(addr), attr); } -static void setTextAttribute(JNIEnv* env, jclass, jint addr, jint javaAttr, jstring javaValue) { +static void NativeDecimalFormat_setTextAttribute(JNIEnv* env, jclass, jint addr, jint javaAttr, jstring javaValue) { ScopedJavaUnicodeString value(env, javaValue); UnicodeString& s(value.unicodeString()); UErrorCode status = U_ZERO_ERROR; @@ -150,7 +150,7 @@ static void setTextAttribute(JNIEnv* env, jclass, jint addr, jint javaAttr, jstr icu4jni_error(env, status); } -static jstring getTextAttribute(JNIEnv* env, jclass, jint addr, jint javaAttr) { +static jstring NativeDecimalFormat_getTextAttribute(JNIEnv* env, jclass, jint addr, jint javaAttr) { UErrorCode status = U_ZERO_ERROR; UNumberFormat* fmt = toUNumberFormat(addr); UNumberFormatTextAttribute attr = static_cast<UNumberFormatTextAttribute>(javaAttr); @@ -169,7 +169,7 @@ static jstring getTextAttribute(JNIEnv* env, jclass, jint addr, jint javaAttr) { return icu4jni_error(env, status) ? NULL : env->NewString(chars.get(), charCount); } -static void applyPatternImpl(JNIEnv* env, jclass, jint addr, jboolean localized, jstring pattern0) { +static void NativeDecimalFormat_applyPatternImpl(JNIEnv* env, jclass, jint addr, jboolean localized, jstring pattern0) { if (pattern0 == NULL) { jniThrowNullPointerException(env, NULL); return; @@ -185,7 +185,7 @@ static void applyPatternImpl(JNIEnv* env, jclass, jint addr, jboolean localized, icu4jni_error(env, status); } -static jstring toPatternImpl(JNIEnv* env, jclass, jint addr, jboolean localized) { +static jstring NativeDecimalFormat_toPatternImpl(JNIEnv* env, jclass, jint addr, jboolean localized) { DecimalFormat* fmt = toDecimalFormat(addr); UnicodeString pattern; if (localized) { @@ -227,17 +227,17 @@ static jstring format(JNIEnv* env, jint addr, jobject fpIter, T val) { return formatResult(env, str, pfpi, fpIter); } -static jstring formatLong(JNIEnv* env, jclass, jint addr, jlong value, jobject fpIter) { +static jstring NativeDecimalFormat_formatLong(JNIEnv* env, jclass, jint addr, jlong value, jobject fpIter) { int64_t longValue = value; return format(env, addr, fpIter, (jlong) longValue); } -static jstring formatDouble(JNIEnv* env, jclass, jint addr, jdouble value, jobject fpIter) { +static jstring NativeDecimalFormat_formatDouble(JNIEnv* env, jclass, jint addr, jdouble value, jobject fpIter) { double doubleValue = value; return format(env, addr, fpIter, (jdouble) doubleValue); } -static jstring formatDigitList(JNIEnv* env, jclass, jint addr, jstring value, jobject fpIter) { +static jstring NativeDecimalFormat_formatDigitList(JNIEnv* env, jclass, jint addr, jstring value, jobject fpIter) { ScopedUtfChars chars(env, value); if (chars.c_str() == NULL) { return NULL; @@ -258,8 +258,8 @@ static jobject newBigDecimal(JNIEnv* env, const char* value, jsize len) { return env->NewObject(JniConstants::bigDecimalClass, gBigDecimal_init, str); } -static jobject parse(JNIEnv* env, jclass, jint addr, jstring text, - jobject position, jboolean parseBigDecimal) { +static jobject NativeDecimalFormat_parse(JNIEnv* env, jclass, jint addr, jstring text, + jobject position, jboolean parseBigDecimal) { static jmethodID gPP_getIndex = env->GetMethodID(JniConstants::parsePositionClass, "getIndex", "()I"); static jmethodID gPP_setIndex = env->GetMethodID(JniConstants::parsePositionClass, "setIndex", "(I)V"); @@ -323,32 +323,30 @@ static jobject parse(JNIEnv* env, jclass, jint addr, jstring text, } } -static jint cloneDecimalFormatImpl(JNIEnv*, jclass, jint addr) { +static jint NativeDecimalFormat_cloneImpl(JNIEnv*, jclass, jint addr) { DecimalFormat* fmt = toDecimalFormat(addr); return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt->clone())); } static JNINativeMethod gMethods[] = { - {"applyPatternImpl", "(IZLjava/lang/String;)V", (void*) applyPatternImpl}, - {"cloneDecimalFormatImpl", "(I)I", (void*) cloneDecimalFormatImpl}, - {"closeDecimalFormatImpl", "(I)V", (void*) closeDecimalFormatImpl}, - {"format", "(IDLcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)Ljava/lang/String;", (void*) formatDouble}, - {"format", "(IJLcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)Ljava/lang/String;", (void*) formatLong}, - {"format", "(ILjava/lang/String;Lcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)Ljava/lang/String;", (void*) formatDigitList}, - {"getAttribute", "(II)I", (void*) getAttribute}, - {"getTextAttribute", "(II)Ljava/lang/String;", (void*) getTextAttribute}, - {"openDecimalFormatImpl", "(Ljava/lang/String;Ljava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)I", (void*) openDecimalFormatImpl}, - {"parse", "(ILjava/lang/String;Ljava/text/ParsePosition;Z)Ljava/lang/Number;", (void*) parse}, - {"setAttribute", "(III)V", (void*) setAttribute}, - {"setDecimalFormatSymbols", "(ILjava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)V", (void*) setDecimalFormatSymbols}, - {"setSymbol", "(IILjava/lang/String;)V", (void*) setSymbol}, - {"setRoundingMode", "(IID)V", (void*) setRoundingMode}, - {"setTextAttribute", "(IILjava/lang/String;)V", (void*) setTextAttribute}, - {"toPatternImpl", "(IZ)Ljava/lang/String;", (void*) toPatternImpl}, + {"applyPatternImpl", "(IZLjava/lang/String;)V", (void*) NativeDecimalFormat_applyPatternImpl}, + {"cloneImpl", "(I)I", (void*) NativeDecimalFormat_cloneImpl}, + {"close", "(I)V", (void*) NativeDecimalFormat_close}, + {"format", "(IDLcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)Ljava/lang/String;", (void*) NativeDecimalFormat_formatDouble}, + {"format", "(IJLcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)Ljava/lang/String;", (void*) NativeDecimalFormat_formatLong}, + {"format", "(ILjava/lang/String;Lcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)Ljava/lang/String;", (void*) NativeDecimalFormat_formatDigitList}, + {"getAttribute", "(II)I", (void*) NativeDecimalFormat_getAttribute}, + {"getTextAttribute", "(II)Ljava/lang/String;", (void*) NativeDecimalFormat_getTextAttribute}, + {"open", "(Ljava/lang/String;Ljava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)I", (void*) NativeDecimalFormat_open}, + {"parse", "(ILjava/lang/String;Ljava/text/ParsePosition;Z)Ljava/lang/Number;", (void*) NativeDecimalFormat_parse}, + {"setAttribute", "(III)V", (void*) NativeDecimalFormat_setAttribute}, + {"setDecimalFormatSymbols", "(ILjava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)V", (void*) NativeDecimalFormat_setDecimalFormatSymbols}, + {"setRoundingMode", "(IID)V", (void*) NativeDecimalFormat_setRoundingMode}, + {"setSymbol", "(IILjava/lang/String;)V", (void*) NativeDecimalFormat_setSymbol}, + {"setTextAttribute", "(IILjava/lang/String;)V", (void*) NativeDecimalFormat_setTextAttribute}, + {"toPatternImpl", "(IZ)Ljava/lang/String;", (void*) NativeDecimalFormat_toPatternImpl}, }; - int register_com_ibm_icu4jni_text_NativeDecimalFormat(JNIEnv* env) { - return jniRegisterNativeMethods(env, - "com/ibm/icu4jni/text/NativeDecimalFormat", gMethods, + return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeDecimalFormat", gMethods, NELEM(gMethods)); } diff --git a/luni/src/main/native/java_io_Console.cpp b/luni/src/main/native/java_io_Console.cpp index 3c80c3d..4d8a5ea 100644 --- a/luni/src/main/native/java_io_Console.cpp +++ b/luni/src/main/native/java_io_Console.cpp @@ -23,11 +23,11 @@ #include <termios.h> #include <unistd.h> -static jboolean java_io_Console_isatty(JNIEnv*, jclass, jint fd) { +static jboolean Console_isatty(JNIEnv*, jclass, jint fd) { return TEMP_FAILURE_RETRY(isatty(fd)); } -static jint java_io_Console_setEcho(JNIEnv* env, jclass, jboolean on, jint previousState) { +static jint Console_setEcho(JNIEnv* env, jclass, jboolean on, jint previousState) { termios state; if (TEMP_FAILURE_RETRY(tcgetattr(STDIN_FILENO, &state)) == -1) { jniThrowIOException(env, errno); @@ -47,8 +47,8 @@ static jint java_io_Console_setEcho(JNIEnv* env, jclass, jboolean on, jint previ } static JNINativeMethod gMethods[] = { - { "isatty", "(I)Z", (void*) java_io_Console_isatty }, - { "setEchoImpl", "(ZI)I", (void*) java_io_Console_setEcho }, + { "isatty", "(I)Z", (void*) Console_isatty }, + { "setEchoImpl", "(ZI)I", (void*) Console_setEcho }, }; int register_java_io_Console(JNIEnv* env) { return jniRegisterNativeMethods(env, "java/io/Console", gMethods, NELEM(gMethods)); diff --git a/luni/src/main/native/java_lang_Math.cpp b/luni/src/main/native/java_lang_Math.cpp index c549f31..42be565 100644 --- a/luni/src/main/native/java_lang_Math.cpp +++ b/luni/src/main/native/java_lang_Math.cpp @@ -22,194 +22,144 @@ #include <stdlib.h> #include <math.h> -/* native public static double sin(double a); */ -static jdouble jsin(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_sin(JNIEnv*, jclass, jdouble a) { return sin(a); } -/* native public static double cos(double a); */ -static jdouble jcos(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_cos(JNIEnv*, jclass, jdouble a) { return cos(a); } -/* native public static double tan(double a); */ -static jdouble jtan(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_tan(JNIEnv*, jclass, jdouble a) { return tan(a); } -/* native public static double asin(double a); */ -static jdouble jasin(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_asin(JNIEnv*, jclass, jdouble a) { return asin(a); } -/* native public static double acos(double a); */ -static jdouble jacos(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_acos(JNIEnv*, jclass, jdouble a) { return acos(a); } -/* native public static double atan(double a); */ -static jdouble jatan(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_atan(JNIEnv*, jclass, jdouble a) { return atan(a); } -/* native public static double exp(double a); */ -static jdouble jexp(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_exp(JNIEnv*, jclass, jdouble a) { return exp(a); } -/* native public static double log(double a); */ -static jdouble jlog(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_log(JNIEnv*, jclass, jdouble a) { return log(a); } -/* native public static double sqrt(double a); */ -static jdouble jsqrt(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_sqrt(JNIEnv*, jclass, jdouble a) { return sqrt(a); } -/* native public static double IEEEremainder(double a, double b); */ -static jdouble jieee_remainder(JNIEnv*, jclass, jdouble a, jdouble b) -{ +static jdouble Math_IEEEremainder(JNIEnv*, jclass, jdouble a, jdouble b) { return remainder(a, b); } -/* native public static double floor(double a); */ -static jdouble jfloor(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_floor(JNIEnv*, jclass, jdouble a) { return floor(a); } -/* native public static double ceil(double a); */ -static jdouble jceil(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_ceil(JNIEnv*, jclass, jdouble a) { return ceil(a); } -/* native public static double rint(double a); */ -static jdouble jrint(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_rint(JNIEnv*, jclass, jdouble a) { return rint(a); } -/* native public static double atan2(double a, double b); */ -static jdouble jatan2(JNIEnv*, jclass, jdouble a, jdouble b) -{ +static jdouble Math_atan2(JNIEnv*, jclass, jdouble a, jdouble b) { return atan2(a, b); } -/* native public static double pow(double a, double b); */ -static jdouble jpow(JNIEnv*, jclass, jdouble a, jdouble b) -{ +static jdouble Math_pow(JNIEnv*, jclass, jdouble a, jdouble b) { return pow(a, b); } -/* native public static double sinh(double a); */ -static jdouble jsinh(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_sinh(JNIEnv*, jclass, jdouble a) { return sinh(a); } -/* native public static double tanh(double a); */ -static jdouble jtanh(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_tanh(JNIEnv*, jclass, jdouble a) { return tanh(a); } -/* native public static double cosh(double a); */ -static jdouble jcosh(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_cosh(JNIEnv*, jclass, jdouble a) { return cosh(a); } -/* native public static double log10(double a); */ -static jdouble jlog10(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_log10(JNIEnv*, jclass, jdouble a) { return log10(a); } -/* native public static double cbrt(double a); */ -static jdouble jcbrt(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_cbrt(JNIEnv*, jclass, jdouble a) { return cbrt(a); } -/* native public static double expm1(double a); */ -static jdouble jexpm1(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_expm1(JNIEnv*, jclass, jdouble a) { return expm1(a); } -/* native public static double hypot(double a, double b); */ -static jdouble jhypot(JNIEnv*, jclass, jdouble a, jdouble b) -{ +static jdouble Math_hypot(JNIEnv*, jclass, jdouble a, jdouble b) { return hypot(a, b); } -/* native public static double log1p(double a); */ -static jdouble jlog1p(JNIEnv*, jclass, jdouble a) -{ +static jdouble Math_log1p(JNIEnv*, jclass, jdouble a) { return log1p(a); } -/* native public static double nextafter(double a, double b); */ -static jdouble jnextafter(JNIEnv*, jclass, jdouble a, jdouble b) -{ +static jdouble Math_nextafter(JNIEnv*, jclass, jdouble a, jdouble b) { return nextafter(a, b); } -/* native public static float nextafterf(float a, float b); */ -static jfloat jnextafterf(JNIEnv*, jclass, jfloat a, jfloat b) -{ +static jfloat Math_nextafterf(JNIEnv*, jclass, jfloat a, jfloat b) { return nextafterf(a, b); } -static jdouble copySign(JNIEnv*, jclass, jdouble a, jdouble b) { +static jdouble Math_copySign(JNIEnv*, jclass, jdouble a, jdouble b) { // Our StrictMath.copySign delegates to Math.copySign, so we need to treat NaN as positive. return copysign(a, isnan(b) ? 1.0 : b); } -static jfloat copySign_f(JNIEnv*, jclass, jfloat a, jfloat b) { +static jfloat Math_copySign_f(JNIEnv*, jclass, jfloat a, jfloat b) { // Our StrictMath.copySign delegates to Math.copySign, so we need to treat NaN as positive. return copysignf(a, isnan(b) ? 1.0 : b); } static JNINativeMethod gMethods[] = { - { "IEEEremainder", "(DD)D", (void*)jieee_remainder }, - { "acos", "(D)D", (void*)jacos }, - { "asin", "(D)D", (void*)jasin }, - { "atan", "(D)D", (void*)jatan }, - { "atan2", "(DD)D", (void*)jatan2 }, - { "cbrt", "(D)D", (void*)jcbrt }, - { "ceil", "(D)D", (void*)jceil }, - { "copySign", "(DD)D", (void*)copySign }, - { "copySign", "(FF)F", (void*)copySign_f }, - { "cos", "(D)D", (void*)jcos }, - { "cosh", "(D)D", (void*)jcosh }, - { "exp", "(D)D", (void*)jexp }, - { "expm1", "(D)D", (void*)jexpm1 }, - { "floor", "(D)D", (void*)jfloor }, - { "hypot", "(DD)D", (void*)jhypot }, - { "log", "(D)D", (void*)jlog }, - { "log10", "(D)D", (void*)jlog10 }, - { "log1p", "(D)D", (void*)jlog1p }, - { "nextafter", "(DD)D", (void*)jnextafter }, - { "nextafterf", "(FF)F", (void*)jnextafterf }, - { "pow", "(DD)D", (void*)jpow }, - { "rint", "(D)D", (void*)jrint }, - { "sin", "(D)D", (void*)jsin }, - { "sinh", "(D)D", (void*)jsinh }, - { "sqrt", "(D)D", (void*)jsqrt }, - { "tan", "(D)D", (void*)jtan }, - { "tanh", "(D)D", (void*)jtanh }, + { "IEEEremainder", "(DD)D", (void*) Math_IEEEremainder }, + { "acos", "(D)D", (void*) Math_acos }, + { "asin", "(D)D", (void*) Math_asin }, + { "atan", "(D)D", (void*) Math_atan }, + { "atan2", "(DD)D", (void*) Math_atan2 }, + { "cbrt", "(D)D", (void*) Math_cbrt }, + { "ceil", "(D)D", (void*) Math_ceil }, + { "copySign", "(DD)D", (void*) Math_copySign }, + { "copySign", "(FF)F", (void*) Math_copySign_f }, + { "cos", "(D)D", (void*) Math_cos }, + { "cosh", "(D)D", (void*) Math_cosh }, + { "exp", "(D)D", (void*) Math_exp }, + { "expm1", "(D)D", (void*) Math_expm1 }, + { "floor", "(D)D", (void*) Math_floor }, + { "hypot", "(DD)D", (void*) Math_hypot }, + { "log", "(D)D", (void*) Math_log }, + { "log10", "(D)D", (void*) Math_log10 }, + { "log1p", "(D)D", (void*) Math_log1p }, + { "nextafter", "(DD)D", (void*) Math_nextafter }, + { "nextafterf", "(FF)F", (void*) Math_nextafterf }, + { "pow", "(DD)D", (void*) Math_pow }, + { "rint", "(D)D", (void*) Math_rint }, + { "sin", "(D)D", (void*) Math_sin }, + { "sinh", "(D)D", (void*) Math_sinh }, + { "sqrt", "(D)D", (void*) Math_sqrt }, + { "tan", "(D)D", (void*) Math_tan }, + { "tanh", "(D)D", (void*) Math_tanh }, }; int register_java_lang_Math(JNIEnv* env) { diff --git a/luni/src/main/native/java_lang_ProcessManager.cpp b/luni/src/main/native/java_lang_ProcessManager.cpp index fd0f4cf..669dd62 100644 --- a/luni/src/main/native/java_lang_ProcessManager.cpp +++ b/luni/src/main/native/java_lang_ProcessManager.cpp @@ -50,7 +50,7 @@ static int androidSystemPropertiesFd = -1; #define WAIT_STATUS_STRANGE_ERRNO (-3) // observed an undocumented errno /** Closes a file descriptor. */ -static void java_lang_ProcessManager_close(JNIEnv* env, jclass, jobject javaDescriptor) { +static void ProcessManager_close(JNIEnv* env, jclass, jobject javaDescriptor) { int fd = jniGetFDFromFileDescriptor(env, javaDescriptor); if (TEMP_FAILURE_RETRY(close(fd)) == -1) { jniThrowIOException(env, errno); @@ -60,7 +60,7 @@ static void java_lang_ProcessManager_close(JNIEnv* env, jclass, jobject javaDesc /** * Kills process with the given ID. */ -static void java_lang_ProcessManager_kill(JNIEnv* env, jclass, jint pid) { +static void ProcessManager_kill(JNIEnv* env, jclass, jint pid) { int result = kill((pid_t) pid, SIGKILL); if (result == -1) { jniThrowIOException(env, errno); @@ -70,7 +70,7 @@ static void java_lang_ProcessManager_kill(JNIEnv* env, jclass, jint pid) { /** * Loops indefinitely and calls ProcessManager.onExit() when children exit. */ -static void java_lang_ProcessManager_watchChildren(JNIEnv* env, jobject o) { +static void ProcessManager_watchChildren(JNIEnv* env, jobject o) { if (onExitMethod == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "staticInitialize() must run first."); @@ -329,7 +329,7 @@ static void freeStrings(JNIEnv* env, jobjectArray javaArray, char** array) { /** * Converts Java String[] to char** and delegates to executeProcess(). */ -static pid_t java_lang_ProcessManager_exec( +static pid_t ProcessManager_exec( JNIEnv* env, jclass, jobjectArray javaCommands, jobjectArray javaEnvironment, jstring javaWorkingDirectory, jobject inDescriptor, jobject outDescriptor, jobject errDescriptor, @@ -377,7 +377,7 @@ static pid_t java_lang_ProcessManager_exec( /** * Looks up Java members. */ -static void java_lang_ProcessManager_staticInitialize(JNIEnv* env, +static void ProcessManager_staticInitialize(JNIEnv* env, jclass clazz) { #ifdef ANDROID char* fdString = getenv("ANDROID_PROPERTY_WORKSPACE"); @@ -393,12 +393,12 @@ static void java_lang_ProcessManager_staticInitialize(JNIEnv* env, } static JNINativeMethod methods[] = { - { "close", "(Ljava/io/FileDescriptor;)V", (void*) java_lang_ProcessManager_close }, - { "kill", "(I)V", (void*) java_lang_ProcessManager_kill }, - { "staticInitialize", "()V", (void*) java_lang_ProcessManager_staticInitialize }, - { "watchChildren", "()V", (void*) java_lang_ProcessManager_watchChildren }, + { "close", "(Ljava/io/FileDescriptor;)V", (void*) ProcessManager_close }, + { "kill", "(I)V", (void*) ProcessManager_kill }, + { "staticInitialize", "()V", (void*) ProcessManager_staticInitialize }, + { "watchChildren", "()V", (void*) ProcessManager_watchChildren }, { "exec", "([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;Z)I", - (void*) java_lang_ProcessManager_exec }, + (void*) ProcessManager_exec }, }; int register_java_lang_ProcessManager(JNIEnv* env) { return jniRegisterNativeMethods(env, "java/lang/ProcessManager", methods, NELEM(methods)); diff --git a/luni/src/main/native/java_net_NetworkInterface.cpp b/luni/src/main/native/java_net_NetworkInterface.cpp index 3a224e1..c4bb92d 100644 --- a/luni/src/main/native/java_net_NetworkInterface.cpp +++ b/luni/src/main/native/java_net_NetworkInterface.cpp @@ -88,7 +88,7 @@ static jobject makeInterfaceAddress(JNIEnv* env, jint interfaceIndex, ifaddrs* i interfaceIndex, javaName, javaAddress, javaMask); } -static jobjectArray getAllInterfaceAddressesImpl(JNIEnv* env, jclass) { +static jobjectArray NetworkInterface_getAllInterfaceAddressesImpl(JNIEnv* env, jclass) { // Get the list of interface addresses. ScopedInterfaceAddresses addresses; if (!addresses.init()) { @@ -173,7 +173,7 @@ static jboolean hasFlag(JNIEnv* env, jstring name, int flag) { return (ifr.ifr_flags & flag) != 0; } -static jbyteArray getHardwareAddressImpl(JNIEnv* env, jclass, jstring name) { +static jbyteArray NetworkInterface_getHardwareAddressImpl(JNIEnv* env, jclass, jstring name) { ifreq ifr; if (!doIoctl(env, name, SIOCGIFHWADDR, ifr)) { return NULL; @@ -194,36 +194,36 @@ static jbyteArray getHardwareAddressImpl(JNIEnv* env, jclass, jstring name) { return result; } -static jint getMTUImpl(JNIEnv* env, jclass, jstring name) { +static jint NetworkInterface_getMTUImpl(JNIEnv* env, jclass, jstring name) { ifreq ifr; doIoctl(env, name, SIOCGIFMTU, ifr); // May throw. return ifr.ifr_mtu; } -static jboolean isLoopbackImpl(JNIEnv* env, jclass, jstring name) { +static jboolean NetworkInterface_isLoopbackImpl(JNIEnv* env, jclass, jstring name) { return hasFlag(env, name, IFF_LOOPBACK); } -static jboolean isPointToPointImpl(JNIEnv* env, jclass, jstring name) { +static jboolean NetworkInterface_isPointToPointImpl(JNIEnv* env, jclass, jstring name) { return hasFlag(env, name, IFF_POINTOPOINT); // Unix API typo! } -static jboolean isUpImpl(JNIEnv* env, jclass, jstring name) { +static jboolean NetworkInterface_isUpImpl(JNIEnv* env, jclass, jstring name) { return hasFlag(env, name, IFF_UP); } -static jboolean supportsMulticastImpl(JNIEnv* env, jclass, jstring name) { +static jboolean NetworkInterface_supportsMulticastImpl(JNIEnv* env, jclass, jstring name) { return hasFlag(env, name, IFF_MULTICAST); } static JNINativeMethod gMethods[] = { - { "getAllInterfaceAddressesImpl", "()[Ljava/net/InterfaceAddress;", (void*) getAllInterfaceAddressesImpl }, - { "getHardwareAddressImpl", "(Ljava/lang/String;)[B", (void*) getHardwareAddressImpl }, - { "getMTUImpl", "(Ljava/lang/String;)I", (void*) getMTUImpl }, - { "isLoopbackImpl", "(Ljava/lang/String;)Z", (void*) isLoopbackImpl }, - { "isPointToPointImpl", "(Ljava/lang/String;)Z", (void*) isPointToPointImpl }, - { "isUpImpl", "(Ljava/lang/String;)Z", (void*) isUpImpl }, - { "supportsMulticastImpl", "(Ljava/lang/String;)Z", (void*) supportsMulticastImpl }, + { "getAllInterfaceAddressesImpl", "()[Ljava/net/InterfaceAddress;", (void*) NetworkInterface_getAllInterfaceAddressesImpl }, + { "getHardwareAddressImpl", "(Ljava/lang/String;)[B", (void*) NetworkInterface_getHardwareAddressImpl }, + { "getMTUImpl", "(Ljava/lang/String;)I", (void*) NetworkInterface_getMTUImpl }, + { "isLoopbackImpl", "(Ljava/lang/String;)Z", (void*) NetworkInterface_isLoopbackImpl }, + { "isPointToPointImpl", "(Ljava/lang/String;)Z", (void*) NetworkInterface_isPointToPointImpl }, + { "isUpImpl", "(Ljava/lang/String;)Z", (void*) NetworkInterface_isUpImpl }, + { "supportsMulticastImpl", "(Ljava/lang/String;)Z", (void*) NetworkInterface_supportsMulticastImpl }, }; int register_java_net_NetworkInterface(JNIEnv* env) { return jniRegisterNativeMethods(env, "java/net/NetworkInterface", gMethods, NELEM(gMethods)); diff --git a/luni/src/main/native/java_util_regex_Matcher.cpp b/luni/src/main/native/java_util_regex_Matcher.cpp index c47a211..b0e5e44 100644 --- a/luni/src/main/native/java_util_regex_Matcher.cpp +++ b/luni/src/main/native/java_util_regex_Matcher.cpp @@ -117,11 +117,11 @@ private: void operator=(const MatcherAccessor&); }; -static void RegexMatcher_closeImpl(JNIEnv*, jclass, jint addr) { +static void Matcher_closeImpl(JNIEnv*, jclass, jint addr) { delete toRegexMatcher(addr); } -static jint RegexMatcher_findImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jint startIndex, jintArray offsets) { +static jint Matcher_findImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jint startIndex, jintArray offsets) { MatcherAccessor matcher(env, addr, javaText, false); UBool result = matcher->find(startIndex, matcher.status()); if (result) { @@ -130,7 +130,7 @@ static jint RegexMatcher_findImpl(JNIEnv* env, jclass, jint addr, jstring javaTe return result; } -static jint RegexMatcher_findNextImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jintArray offsets) { +static jint Matcher_findNextImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jintArray offsets) { MatcherAccessor matcher(env, addr, javaText, false); if (matcher.status() != U_ZERO_ERROR) { return -1; @@ -142,17 +142,17 @@ static jint RegexMatcher_findNextImpl(JNIEnv* env, jclass, jint addr, jstring ja return result; } -static jint RegexMatcher_groupCountImpl(JNIEnv* env, jclass, jint addr) { +static jint Matcher_groupCountImpl(JNIEnv* env, jclass, jint addr) { MatcherAccessor matcher(env, addr); return matcher->groupCount(); } -static jint RegexMatcher_hitEndImpl(JNIEnv* env, jclass, jint addr) { +static jint Matcher_hitEndImpl(JNIEnv* env, jclass, jint addr) { MatcherAccessor matcher(env, addr); return matcher->hitEnd(); } -static jint RegexMatcher_lookingAtImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jintArray offsets) { +static jint Matcher_lookingAtImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jintArray offsets) { MatcherAccessor matcher(env, addr, javaText, false); UBool result = matcher->lookingAt(matcher.status()); if (result) { @@ -161,7 +161,7 @@ static jint RegexMatcher_lookingAtImpl(JNIEnv* env, jclass, jint addr, jstring j return result; } -static jint RegexMatcher_matchesImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jintArray offsets) { +static jint Matcher_matchesImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jintArray offsets) { MatcherAccessor matcher(env, addr, javaText, false); UBool result = matcher->matches(matcher.status()); if (result) { @@ -170,7 +170,7 @@ static jint RegexMatcher_matchesImpl(JNIEnv* env, jclass, jint addr, jstring jav return result; } -static jint RegexMatcher_openImpl(JNIEnv* env, jclass, jint patternAddr) { +static jint Matcher_openImpl(JNIEnv* env, jclass, jint patternAddr) { RegexPattern* pattern = reinterpret_cast<RegexPattern*>(static_cast<uintptr_t>(patternAddr)); UErrorCode status = U_ZERO_ERROR; RegexMatcher* result = pattern->matcher(status); @@ -178,39 +178,39 @@ static jint RegexMatcher_openImpl(JNIEnv* env, jclass, jint patternAddr) { return static_cast<jint>(reinterpret_cast<uintptr_t>(result)); } -static jint RegexMatcher_requireEndImpl(JNIEnv* env, jclass, jint addr) { +static jint Matcher_requireEndImpl(JNIEnv* env, jclass, jint addr) { MatcherAccessor matcher(env, addr); return matcher->requireEnd(); } -static void RegexMatcher_setInputImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jint start, jint end) { +static void Matcher_setInputImpl(JNIEnv* env, jclass, jint addr, jstring javaText, jint start, jint end) { MatcherAccessor matcher(env, addr, javaText, true); matcher->region(start, end, matcher.status()); } -static void RegexMatcher_useAnchoringBoundsImpl(JNIEnv* env, jclass, jint addr, jboolean value) { +static void Matcher_useAnchoringBoundsImpl(JNIEnv* env, jclass, jint addr, jboolean value) { MatcherAccessor matcher(env, addr); matcher->useAnchoringBounds(value); } -static void RegexMatcher_useTransparentBoundsImpl(JNIEnv* env, jclass, jint addr, jboolean value) { +static void Matcher_useTransparentBoundsImpl(JNIEnv* env, jclass, jint addr, jboolean value) { MatcherAccessor matcher(env, addr); matcher->useTransparentBounds(value); } static JNINativeMethod gMethods[] = { - { "closeImpl", "(I)V", (void*) RegexMatcher_closeImpl }, - { "findImpl", "(ILjava/lang/String;I[I)Z", (void*) RegexMatcher_findImpl }, - { "findNextImpl", "(ILjava/lang/String;[I)Z", (void*) RegexMatcher_findNextImpl }, - { "groupCountImpl", "(I)I", (void*) RegexMatcher_groupCountImpl }, - { "hitEndImpl", "(I)Z", (void*) RegexMatcher_hitEndImpl }, - { "lookingAtImpl", "(ILjava/lang/String;[I)Z", (void*) RegexMatcher_lookingAtImpl }, - { "matchesImpl", "(ILjava/lang/String;[I)Z", (void*) RegexMatcher_matchesImpl }, - { "openImpl", "(I)I", (void*) RegexMatcher_openImpl }, - { "requireEndImpl", "(I)Z", (void*) RegexMatcher_requireEndImpl }, - { "setInputImpl", "(ILjava/lang/String;II)V", (void*) RegexMatcher_setInputImpl }, - { "useAnchoringBoundsImpl", "(IZ)V", (void*) RegexMatcher_useAnchoringBoundsImpl }, - { "useTransparentBoundsImpl", "(IZ)V", (void*) RegexMatcher_useTransparentBoundsImpl }, + { "closeImpl", "(I)V", (void*) Matcher_closeImpl }, + { "findImpl", "(ILjava/lang/String;I[I)Z", (void*) Matcher_findImpl }, + { "findNextImpl", "(ILjava/lang/String;[I)Z", (void*) Matcher_findNextImpl }, + { "groupCountImpl", "(I)I", (void*) Matcher_groupCountImpl }, + { "hitEndImpl", "(I)Z", (void*) Matcher_hitEndImpl }, + { "lookingAtImpl", "(ILjava/lang/String;[I)Z", (void*) Matcher_lookingAtImpl }, + { "matchesImpl", "(ILjava/lang/String;[I)Z", (void*) Matcher_matchesImpl }, + { "openImpl", "(I)I", (void*) Matcher_openImpl }, + { "requireEndImpl", "(I)Z", (void*) Matcher_requireEndImpl }, + { "setInputImpl", "(ILjava/lang/String;II)V", (void*) Matcher_setInputImpl }, + { "useAnchoringBoundsImpl", "(IZ)V", (void*) Matcher_useAnchoringBoundsImpl }, + { "useTransparentBoundsImpl", "(IZ)V", (void*) Matcher_useTransparentBoundsImpl }, }; int register_java_util_regex_Matcher(JNIEnv* env) { return jniRegisterNativeMethods(env, "java/util/regex/Matcher", gMethods, NELEM(gMethods)); diff --git a/luni/src/main/native/java_util_regex_Pattern.cpp b/luni/src/main/native/java_util_regex_Pattern.cpp index 9d48b08..b03d564 100644 --- a/luni/src/main/native/java_util_regex_Pattern.cpp +++ b/luni/src/main/native/java_util_regex_Pattern.cpp @@ -41,11 +41,11 @@ static void throwPatternSyntaxException(JNIEnv* env, UErrorCode status, jstring env->Throw(reinterpret_cast<jthrowable>(exception)); } -static void RegexPattern_closeImpl(JNIEnv*, jclass, jint addr) { +static void Pattern_closeImpl(JNIEnv*, jclass, jint addr) { delete toRegexPattern(addr); } -static jint RegexPattern_compileImpl(JNIEnv* env, jclass, jstring javaRegex, jint flags) { +static jint Pattern_compileImpl(JNIEnv* env, jclass, jstring javaRegex, jint flags) { flags |= UREGEX_ERROR_ON_UNKNOWN_ESCAPES; UErrorCode status = U_ZERO_ERROR; @@ -62,8 +62,8 @@ static jint RegexPattern_compileImpl(JNIEnv* env, jclass, jstring javaRegex, jin } static JNINativeMethod gMethods[] = { - { "closeImpl", "(I)V", (void*) RegexPattern_closeImpl }, - { "compileImpl", "(Ljava/lang/String;I)I", (void*) RegexPattern_compileImpl }, + { "closeImpl", "(I)V", (void*) Pattern_closeImpl }, + { "compileImpl", "(Ljava/lang/String;I)I", (void*) Pattern_compileImpl }, }; int register_java_util_regex_Pattern(JNIEnv* env) { return jniRegisterNativeMethods(env, "java/util/regex/Pattern", gMethods, NELEM(gMethods)); diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp index edfaba0..960b581 100644 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp @@ -18,12 +18,12 @@ #include "JNIHelp.h" #include "JniConstants.h" -#include "utils/misc.h" -#include "utils/Log.h" -#include <sys/mman.h> +#include "UniquePtr.h" + +#include <errno.h> #include <stdlib.h> #include <string.h> -#include <errno.h> +#include <sys/mman.h> /* * Cached dalvik.system.VMRuntime pieces. @@ -39,138 +39,82 @@ static const int MMAP_READ_ONLY = 1; static const int MMAP_READ_WRITE = 2; static const int MMAP_WRITE_COPY = 4; -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: littleEndian - * Signature: ()Z - */ -static jboolean harmony_nio_littleEndian(JNIEnv*, jclass) { +template <typename T> static T cast(jint address) { + return reinterpret_cast<T>(static_cast<uintptr_t>(address)); +} + +static jboolean OSMemory_isLittleEndianImpl(JNIEnv*, jclass) { long l = 0x01020304; - unsigned char* c = (unsigned char*)&l; + unsigned char* c = reinterpret_cast<unsigned char*>(&l); return (*c == 0x04) ? JNI_TRUE : JNI_FALSE; } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getPointerSizeImpl - * Signature: ()I - */ -static jint harmony_nio_getPointerSizeImpl(JNIEnv*, jclass) { - return sizeof(void *); +static jint OSMemory_getPointerSizeImpl(JNIEnv*, jclass) { + return sizeof(void*); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: mallocImpl - * Signature: (I)I - */ -static jint harmony_nio_mallocImpl(JNIEnv* _env, jobject, jint size) { - jboolean allowed = _env->CallBooleanMethod(gIDCache.runtimeInstance, +static jint OSMemory_malloc(JNIEnv* env, jobject, jint size) { + jboolean allowed = env->CallBooleanMethod(gIDCache.runtimeInstance, gIDCache.method_trackExternalAllocation, (jlong) size); if (!allowed) { LOGW("External allocation of %d bytes was rejected\n", size); - jniThrowException(_env, "java/lang/OutOfMemoryError", NULL); + jniThrowException(env, "java/lang/OutOfMemoryError", NULL); return 0; } LOGV("OSMemory alloc %d\n", size); - void *returnValue = malloc(size + sizeof(jlong)); - if (returnValue == NULL) { - jniThrowException(_env, "java/lang/OutOfMemoryError", NULL); + void* block = malloc(size + sizeof(jlong)); + if (block == NULL) { + jniThrowException(env, "java/lang/OutOfMemoryError", NULL); return 0; } /* * Tuck a copy of the size at the head of the buffer. We need this - * so harmony_nio_freeImpl() knows how much memory is being freed. + * so OSMemory_free() knows how much memory is being freed. */ - jlong* adjptr = (jlong*) returnValue; - *adjptr++ = size; - return (jint)adjptr; + jlong* result = reinterpret_cast<jlong*>(block); + *result++ = size; + return static_cast<jint>(reinterpret_cast<uintptr_t>(result)); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: freeImpl - * Signature: (I)V - */ -static void harmony_nio_freeImpl(JNIEnv* _env, jobject, jint pointer) { - jlong* adjptr = (jlong*) pointer; - jint size = *--adjptr; - LOGV("OSMemory free %d\n", size); - _env->CallVoidMethod(gIDCache.runtimeInstance, - gIDCache.method_trackExternalFree, (jlong) size); - free((void *)adjptr); +static void OSMemory_free(JNIEnv* env, jobject, jint address) { + jlong* p = reinterpret_cast<jlong*>(static_cast<uintptr_t>(address)); + jlong size = *--p; + LOGV("OSMemory free %ld\n", size); + env->CallVoidMethod(gIDCache.runtimeInstance, gIDCache.method_trackExternalFree, size); + free(reinterpret_cast<void*>(p)); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: memset - * Signature: (IBJ)V - */ -static void harmony_nio_memset(JNIEnv*, jobject, jint address, - jbyte value, jlong length) { - memset ((void *) ((jint) address), (jbyte) value, (jlong) length); +static void OSMemory_memset(JNIEnv*, jobject, jint dstAddress, jbyte value, jlong length) { + memset(cast<void*>(dstAddress), value, length); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: memmove - * Signature: (IIJ)V - */ -static void harmony_nio_memmove(JNIEnv*, jobject, jint destAddress, - jint srcAddress, jlong length) { - memmove ((void *) ((jint) destAddress), (const void *) ((jint) srcAddress), - (jlong) length); +static void OSMemory_memmove(JNIEnv*, jobject, jint dstAddress, jint srcAddress, jlong length) { + memmove(cast<void*>(dstAddress), cast<const void*>(srcAddress), length); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getByteImpl - * Signature: (I)B - */ -static jbyte harmony_nio_getByteImpl(JNIEnv*, jobject, - jint pointer) { - jbyte returnValue = *((jbyte *)pointer); - return returnValue; +static jbyte OSMemory_getByte(JNIEnv*, jobject, jint srcAddress) { + return *cast<const jbyte*>(srcAddress); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getBytesImpl - * Signature: (I[BII)V - */ -static void harmony_nio_getBytesImpl(JNIEnv* _env, jobject, jint pointer, +static void OSMemory_getByteArray(JNIEnv* env, jobject, jint srcAddress, jbyteArray dst, jint offset, jint length) { - jbyte* src = reinterpret_cast<jbyte*>(static_cast<uintptr_t>(pointer)); - _env->SetByteArrayRegion(dst, offset, length, src); + env->SetByteArrayRegion(dst, offset, length, cast<const jbyte*>(srcAddress)); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: putByteImpl - * Signature: (IB)V - */ -static void harmony_nio_putByteImpl(JNIEnv*, jobject, jint pointer, - jbyte val) { - *((jbyte *)pointer) = val; +static void OSMemory_setByte(JNIEnv*, jobject, jint dstAddress, jbyte value) { + *cast<jbyte*>(dstAddress) = value; } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: putBytesImpl - * Signature: (I[BII)V - */ -static void harmony_nio_putBytesImpl(JNIEnv* _env, jobject, - jint pointer, jbyteArray src, jint offset, jint length) { - jbyte* dst = reinterpret_cast<jbyte*>(static_cast<uintptr_t>(pointer)); - _env->GetByteArrayRegion(src, offset, length, dst); +static void OSMemory_setByteArray(JNIEnv* env, jobject, + jint dstAddress, jbyteArray src, jint offset, jint length) { + env->GetByteArrayRegion(src, offset, length, cast<jbyte*>(dstAddress)); } -static void -swapShorts(jshort *shorts, int count) { - jbyte *src = (jbyte *) shorts; - jbyte *dst = src; +static void swapShorts(jshort* shorts, int count) { + jbyte* src = reinterpret_cast<jbyte*>(shorts); + jbyte* dst = src; for (int i = 0; i < count; ++i) { jbyte b0 = *src++; jbyte b1 = *src++; @@ -179,10 +123,9 @@ swapShorts(jshort *shorts, int count) { } } -static void -swapInts(jint *ints, int count) { - jbyte *src = (jbyte *) ints; - jbyte *dst = src; +static void swapInts(jint* ints, int count) { + jbyte* src = reinterpret_cast<jbyte*>(ints); + jbyte* dst = src; for (int i = 0; i < count; ++i) { jbyte b0 = *src++; jbyte b1 = *src++; @@ -195,108 +138,73 @@ swapInts(jint *ints, int count) { } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: setShortArrayImpl - * Signature: (I[SIIZ)V - */ -static void harmony_nio_setShortArrayImpl(JNIEnv* _env, jobject, - jint pointer, jshortArray src, jint offset, jint length, jboolean swap) { - jshort* dst = reinterpret_cast<jshort*>(static_cast<uintptr_t>(pointer)); - _env->GetShortArrayRegion(src, offset, length, dst); +static void OSMemory_setShortArray(JNIEnv* env, jobject, + jint dstAddress, jshortArray src, jint offset, jint length, jboolean swap) { + jshort* dst = cast<jshort*>(dstAddress); + env->GetShortArrayRegion(src, offset, length, dst); if (swap) { swapShorts(dst, length); } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: setIntArrayImpl - * Signature: (I[IIIZ)V - */ -static void harmony_nio_setIntArrayImpl(JNIEnv* _env, jobject, - jint pointer, jintArray src, jint offset, jint length, jboolean swap) { - jint* dst = reinterpret_cast<jint*>(static_cast<uintptr_t>(pointer)); - _env->GetIntArrayRegion(src, offset, length, dst); +static void OSMemory_setIntArray(JNIEnv* env, jobject, + jint dstAddress, jintArray src, jint offset, jint length, jboolean swap) { + jint* dst = cast<jint*>(dstAddress); + env->GetIntArrayRegion(src, offset, length, dst); if (swap) { swapInts(dst, length); } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getShortImpl - * Signature: (I)S - */ -static jshort harmony_nio_getShortImpl(JNIEnv*, jobject, - jint pointer) { - if ((pointer & 0x1) == 0) { - jshort returnValue = *((jshort *)pointer); - return returnValue; +static jshort OSMemory_getShort(JNIEnv*, jobject, jint srcAddress) { + if ((srcAddress & 0x1) == 0) { + return *cast<const jshort*>(srcAddress); } else { // Handle unaligned memory access one byte at a time - jshort s; - unsigned char *src = (unsigned char *) pointer; - unsigned char *dst = (unsigned char *) &s; + jshort result; + const jbyte* src = cast<const jbyte*>(srcAddress); + jbyte* dst = reinterpret_cast<jbyte*>(&result); dst[0] = src[0]; dst[1] = src[1]; - return s; + return result; } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: petShortImpl - * Signature: (IS)V - */ -static void harmony_nio_putShortImpl(JNIEnv*, jobject, jint pointer, - jshort value) { - if ((pointer & 0x1) == 0) { - *((jshort *)pointer) = value; +static void OSMemory_setShort(JNIEnv*, jobject, jint dstAddress, jshort value) { + if ((dstAddress & 0x1) == 0) { + *cast<jshort*>(dstAddress) = value; } else { // Handle unaligned memory access one byte at a time - unsigned char *src = (unsigned char *) &value; - unsigned char *dst = (unsigned char *) pointer; + const jbyte* src = reinterpret_cast<const jbyte*>(&value); + jbyte* dst = cast<jbyte*>(dstAddress); dst[0] = src[0]; dst[1] = src[1]; } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getIntImpl - * Signature: (I)I - */ -static jint harmony_nio_getIntImpl(JNIEnv*, jobject, jint pointer) { - if ((pointer & 0x3) == 0) { - jint returnValue = *((jint *)pointer); - return returnValue; +static jint OSMemory_getInt(JNIEnv*, jobject, jint srcAddress) { + if ((srcAddress & 0x3) == 0) { + return *cast<const jint*>(srcAddress); } else { // Handle unaligned memory access one byte at a time - jint i; - unsigned char *src = (unsigned char *) pointer; - unsigned char *dst = (unsigned char *) &i; + jint result; + const jbyte* src = cast<const jbyte*>(srcAddress); + jbyte* dst = reinterpret_cast<jbyte*>(&result); dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; dst[3] = src[3]; - return i; + return result; } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: putIntImpl - * Signature: (II)V - */ -static void harmony_nio_putIntImpl(JNIEnv*, jobject, jint pointer, - jint value) { - if ((pointer & 0x3) == 0) { - *((jint *)pointer) = value; +static void OSMemory_setInt(JNIEnv*, jobject, jint dstAddress, jint value) { + if ((dstAddress & 0x3) == 0) { + *cast<jint*>(dstAddress) = value; } else { // Handle unaligned memory access one byte at a time - unsigned char *src = (unsigned char *) &value; - unsigned char *dst = (unsigned char *) pointer; + const jbyte* src = reinterpret_cast<const jbyte*>(&value); + jbyte* dst = cast<jbyte*>(dstAddress); dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; @@ -304,131 +212,57 @@ static void harmony_nio_putIntImpl(JNIEnv*, jobject, jint pointer, } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getLongImpl - * Signature: (I)Ljava/lang/Long; - */ -static jlong harmony_nio_getLongImpl(JNIEnv*, jobject, - jint pointer) { - if ((pointer & 0x7) == 0) { - jlong returnValue = *((jlong *)pointer); - return returnValue; +template <typename T> static T get(jint srcAddress) { + if ((srcAddress & (sizeof(T) - 1)) == 0) { + return *cast<const T*>(srcAddress); } else { - // Handle unaligned memory access one byte at a time - jlong l; - memcpy((void *) &l, (void *) pointer, sizeof(jlong)); - return l; + T result; + memcpy(&result, cast<const T*>(srcAddress), sizeof(T)); + return result; } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: putLongImpl - * Signature: (IJ)V - */ -static void harmony_nio_putLongImpl(JNIEnv*, jobject, jint pointer, - jlong value) { - if ((pointer & 0x7) == 0) { - *((jlong *)pointer) = value; +template <typename T> static void set(jint dstAddress, T value) { + if ((dstAddress & (sizeof(T) - 1)) == 0) { + *cast<T*>(dstAddress) = value; } else { - // Handle unaligned memory access one byte at a time - memcpy((void *) pointer, (void *) &value, sizeof(jlong)); + memcpy(cast<void*>(dstAddress), &value, sizeof(T)); } } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getFloatImpl - * Signature: (I)F - */ -static jfloat harmony_nio_getFloatImpl(JNIEnv*, jobject, - jint pointer) { - if ((pointer & 0x3) == 0) { - jfloat returnValue = *((jfloat *)pointer); - return returnValue; - } else { - // Handle unaligned memory access one byte at a time - jfloat f; - memcpy((void *) &f, (void *) pointer, sizeof(jfloat)); - return f; - } +static jlong OSMemory_getLong(JNIEnv*, jobject, jint srcAddress) { + return get<jlong>(srcAddress); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: setFloatImpl - * Signature: (IF)V - */ -static void harmony_nio_putFloatImpl(JNIEnv*, jobject, jint pointer, - jfloat value) { - if ((pointer & 0x3) == 0) { - *((jfloat *)pointer) = value; - } else { - // Handle unaligned memory access one byte at a time - memcpy((void *) pointer, (void *) &value, sizeof(jfloat)); - } +static void OSMemory_setLong(JNIEnv*, jobject, jint dstAddress, jlong value) { + set<jlong>(dstAddress, value); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getDoubleImpl - * Signature: (I)D - */ -static jdouble harmony_nio_getDoubleImpl(JNIEnv*, jobject, - jint pointer) { - if ((pointer & 0x7) == 0) { - jdouble returnValue = *((jdouble *)pointer); - return returnValue; - } else { - // Handle unaligned memory access one byte at a time - jdouble d; - memcpy((void *) &d, (void *) pointer, sizeof(jdouble)); - return d; - } +static jfloat OSMemory_getFloat(JNIEnv*, jobject, jint srcAddress) { + return get<jfloat>(srcAddress); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: putDoubleImpl - * Signature: (ID)V - */ -static void harmony_nio_putDoubleImpl(JNIEnv*, jobject, jint pointer, - jdouble value) { - if ((pointer & 0x7) == 0) { - *((jdouble *)pointer) = value; - } else { - // Handle unaligned memory access one byte at a time - memcpy((void *) pointer, (void *) &value, sizeof(jdouble)); - } +static void OSMemory_setFloat(JNIEnv*, jobject, jint dstAddress, jfloat value) { + set<jfloat>(dstAddress, value); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: getAddress - * Signature: (I)I - */ -static jint harmony_nio_getAddress(JNIEnv*, jobject, jint pointer) { - return (jint) * (int *) pointer; +static jdouble OSMemory_getDouble(JNIEnv*, jobject, jint srcAddress) { + return get<jdouble>(srcAddress); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: setAddress - * Signature: (II)V - */ -static void harmony_nio_setAddress(JNIEnv*, jobject, jint pointer, - jint value) { - *(int *) pointer = (int) value; +static void OSMemory_setDouble(JNIEnv*, jobject, jint dstAddress, jdouble value) { + set<jdouble>(dstAddress, value); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: mmapImpl - * Signature: (IJJI)I - */ -static jint harmony_nio_mmapImpl(JNIEnv* env, jobject, jint fd, - jlong offset, jlong size, jint mapMode) { +static jint OSMemory_getAddress(JNIEnv*, jobject, jint srcAddress) { + return *cast<const jint*>(srcAddress); +} + +static void OSMemory_setAddress(JNIEnv*, jobject, jint dstAddress, jint value) { + *cast<jint*>(dstAddress) = value; +} + +static jint OSMemory_mmapImpl(JNIEnv* env, jobject, jint fd, jlong offset, jlong size, jint mapMode) { int prot, flags; switch (mapMode) { case MMAP_READ_ONLY: @@ -456,115 +290,80 @@ static jint harmony_nio_mmapImpl(JNIEnv* env, jobject, jint fd, return reinterpret_cast<uintptr_t>(mapAddress); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: unmapImpl - * Signature: (IJ)V - */ -static void harmony_nio_unmapImpl(JNIEnv*, jobject, jint address, - jlong size) { - munmap((void *)address, (size_t)size); +static void OSMemory_unmapImpl(JNIEnv*, jobject, jint address, jlong size) { + munmap(cast<void*>(address), size); } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: loadImpl - * Signature: (IJ)I - */ -static jint harmony_nio_loadImpl(JNIEnv*, jobject, jint address, - jlong size) { - - if(mlock((void *)address, (size_t)size)!=-1) { - if(munlock((void *)address, (size_t)size)!=-1) { +static jint OSMemory_loadImpl(JNIEnv*, jobject, jint address, jlong size) { + if (mlock(cast<void*>(address), size) != -1) { + if (munlock(cast<void*>(address), size) != -1) { return 0; /* normally */ } - } - else { + } else { /* according to linux sys call, only root can mlock memory. */ - if(errno == EPERM) { + if (errno == EPERM) { return 0; } } - return -1; } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: isLoadedImpl - * Signature: (IJ)Z - */ -static jboolean harmony_nio_isLoadedImpl(JNIEnv*, jobject, - jint address, jlong size) { - +static jboolean OSMemory_isLoadedImpl(JNIEnv*, jobject, jint address, jlong size) { static int page_size = getpagesize(); - jboolean result = 0; - jint m_addr = (jint)address; - - int align_offset = m_addr%page_size;// addr should align with the boundary of a page. - m_addr -= align_offset; - size += align_offset; - int page_count = (size+page_size-1)/page_size; - - unsigned char* vec = (unsigned char *) malloc(page_count*sizeof(char)); - - if (mincore((void *)m_addr, size, (MINCORE_POINTER_TYPE) vec)==0) { - // or else there is error about the mincore and return false; - int i; - for(i=0 ;i<page_count;i++) { - if(vec[i]!=1) { - break; - } - } - if(i==page_count) { - result = 1; - } - } - free(vec); + int align_offset = address % page_size;// addr should align with the boundary of a page. + address -= align_offset; + size += align_offset; + int page_count = (size + page_size - 1) / page_size; - return result; + UniquePtr<unsigned char[]> vec(new unsigned char[page_count]); + int rc = mincore(cast<void*>(address), size, (MINCORE_POINTER_TYPE) vec.get()); + if (rc == -1) { + return false; + } + + for (int i = 0; i < page_count; ++i) { + if (vec[i] != 1) { + return false; + } + } + return true; } -/* - * Class: org_apache_harmony_luni_platform_OSMemory - * Method: flushImpl - * Signature: (IJ)I - */ -static jint harmony_nio_flushImpl(JNIEnv *, jobject, jint address, jlong size) { - return msync((void *)address, size, MS_SYNC); +static jint OSMemory_flushImpl(JNIEnv*, jobject, jint address, jlong size) { + return msync(cast<const void*>(address), size, MS_SYNC); } static JNINativeMethod gMethods[] = { - { "isLittleEndianImpl", "()Z", (void*) harmony_nio_littleEndian }, - { "getPointerSizeImpl", "()I", (void*) harmony_nio_getPointerSizeImpl }, - { "malloc", "(I)I", (void*) harmony_nio_mallocImpl }, - { "free", "(I)V", (void*) harmony_nio_freeImpl }, - { "memset", "(IBJ)V", (void*) harmony_nio_memset }, - { "memmove", "(IIJ)V", (void*) harmony_nio_memmove }, - { "getByteArray", "(I[BII)V",(void*) harmony_nio_getBytesImpl }, - { "setByteArray", "(I[BII)V",(void*) harmony_nio_putBytesImpl }, - { "setShortArray", "(I[SIIZ)V",(void*) harmony_nio_setShortArrayImpl }, - { "setIntArray", "(I[IIIZ)V",(void*) harmony_nio_setIntArrayImpl }, - { "getByte", "(I)B", (void*) harmony_nio_getByteImpl }, - { "setByte", "(IB)V", (void*) harmony_nio_putByteImpl }, - { "getShort", "(I)S", (void*) harmony_nio_getShortImpl }, - { "setShort", "(IS)V", (void*) harmony_nio_putShortImpl }, - { "getInt", "(I)I", (void*) harmony_nio_getIntImpl }, - { "setInt", "(II)V", (void*) harmony_nio_putIntImpl }, - { "getLong", "(I)J", (void*) harmony_nio_getLongImpl }, - { "setLong", "(IJ)V", (void*) harmony_nio_putLongImpl }, - { "getFloat", "(I)F", (void*) harmony_nio_getFloatImpl }, - { "setFloat", "(IF)V", (void*) harmony_nio_putFloatImpl }, - { "getDouble", "(I)D", (void*) harmony_nio_getDoubleImpl }, - { "setDouble", "(ID)V", (void*) harmony_nio_putDoubleImpl }, - { "getAddress", "(I)I", (void*) harmony_nio_getAddress }, - { "setAddress", "(II)V", (void*) harmony_nio_setAddress }, - { "mmapImpl", "(IJJI)I", (void*) harmony_nio_mmapImpl }, - { "unmapImpl", "(IJ)V", (void*) harmony_nio_unmapImpl }, - { "loadImpl", "(IJ)I", (void*) harmony_nio_loadImpl }, - { "isLoadedImpl", "(IJ)Z", (void*) harmony_nio_isLoadedImpl }, - { "flushImpl", "(IJ)I", (void*) harmony_nio_flushImpl } + { "flushImpl", "(IJ)I", (void*) OSMemory_flushImpl }, + { "free", "(I)V", (void*) OSMemory_free }, + { "getAddress", "(I)I", (void*) OSMemory_getAddress }, + { "getByte", "(I)B", (void*) OSMemory_getByte }, + { "getByteArray", "(I[BII)V",(void*) OSMemory_getByteArray }, + { "getDouble", "(I)D", (void*) OSMemory_getDouble }, + { "getFloat", "(I)F", (void*) OSMemory_getFloat }, + { "getInt", "(I)I", (void*) OSMemory_getInt }, + { "getLong", "(I)J", (void*) OSMemory_getLong }, + { "getPointerSizeImpl", "()I", (void*) OSMemory_getPointerSizeImpl }, + { "getShort", "(I)S", (void*) OSMemory_getShort }, + { "isLittleEndianImpl", "()Z", (void*) OSMemory_isLittleEndianImpl }, + { "isLoadedImpl", "(IJ)Z", (void*) OSMemory_isLoadedImpl }, + { "loadImpl", "(IJ)I", (void*) OSMemory_loadImpl }, + { "malloc", "(I)I", (void*) OSMemory_malloc }, + { "memmove", "(IIJ)V", (void*) OSMemory_memmove }, + { "memset", "(IBJ)V", (void*) OSMemory_memset }, + { "mmapImpl", "(IJJI)I", (void*) OSMemory_mmapImpl }, + { "setAddress", "(II)V", (void*) OSMemory_setAddress }, + { "setByte", "(IB)V", (void*) OSMemory_setByte }, + { "setByteArray", "(I[BII)V",(void*) OSMemory_setByteArray }, + { "setDouble", "(ID)V", (void*) OSMemory_setDouble }, + { "setFloat", "(IF)V", (void*) OSMemory_setFloat }, + { "setInt", "(II)V", (void*) OSMemory_setInt }, + { "setIntArray", "(I[IIIZ)V",(void*) OSMemory_setIntArray }, + { "setLong", "(IJ)V", (void*) OSMemory_setLong }, + { "setShort", "(IS)V", (void*) OSMemory_setShort }, + { "setShortArray", "(I[SIIZ)V",(void*) OSMemory_setShortArray }, + { "unmapImpl", "(IJ)V", (void*) OSMemory_unmapImpl }, }; int register_org_apache_harmony_luni_platform_OSMemory(JNIEnv* env) { /* |