diff options
author | Ian Rogers <irogers@google.com> | 2014-10-10 11:02:11 -0700 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2014-10-10 12:26:02 -0700 |
commit | 647b1a86f518d8db0331b3d52a96392b7a62504b (patch) | |
tree | 7370f795ef3c7fbdd2695d23bc6f8171f40f43f1 | |
parent | acfbbd4df2fc1c79a7102587bebf398f95b5e5de (diff) | |
download | art-647b1a86f518d8db0331b3d52a96392b7a62504b.zip art-647b1a86f518d8db0331b3d52a96392b7a62504b.tar.gz art-647b1a86f518d8db0331b3d52a96392b7a62504b.tar.bz2 |
Fix 2 new sets of clang compiler warnings.
Fix issues that are flagged by -Wfloat-equal and -Wmissing-noreturn.
In the case of -Wfloat-equal the current cases in regular code are deliberate,
so the change is to silence the warning. For gtest code the appropriate fix is
to switch from EXPECT_EQ to EXPECT_(FLOAT|DOUBLE)_EQ.
The -Wmissing-noreturn warning isn't enabled due to a missing noreturn in
gtest. This issue has been reported to gtest.
Change-Id: Id84c70c21c542716c9ee0c41492e8ff8788c4ef8
-rw-r--r-- | build/Android.common_build.mk | 3 | ||||
-rw-r--r-- | compiler/jni/jni_compiler_test.cc | 18 | ||||
-rw-r--r-- | dex2oat/dex2oat.cc | 3 | ||||
-rw-r--r-- | patchoat/patchoat.cc | 1 | ||||
-rw-r--r-- | runtime/base/histogram-inl.h | 9 | ||||
-rw-r--r-- | runtime/base/histogram_test.cc | 12 | ||||
-rw-r--r-- | runtime/base/macros.h | 1 | ||||
-rw-r--r-- | runtime/class_linker_test.cc | 8 | ||||
-rw-r--r-- | runtime/entrypoints/quick/quick_math_entrypoints.cc | 9 | ||||
-rw-r--r-- | runtime/interpreter/interpreter_goto_table_impl.cc | 9 | ||||
-rw-r--r-- | runtime/interpreter/interpreter_switch_impl.cc | 11 | ||||
-rw-r--r-- | runtime/jni_internal_test.cc | 46 | ||||
-rw-r--r-- | runtime/mirror/object_test.cc | 67 | ||||
-rw-r--r-- | runtime/native/java_lang_Runtime.cc | 1 | ||||
-rw-r--r-- | runtime/parsed_options_test.cc | 2 | ||||
-rw-r--r-- | runtime/reflection_test.cc | 36 | ||||
-rw-r--r-- | runtime/runtime.h | 2 | ||||
-rw-r--r-- | runtime/transaction_test.cc | 24 |
18 files changed, 181 insertions, 81 deletions
diff --git a/build/Android.common_build.mk b/build/Android.common_build.mk index d2d6d23..276e81a 100644 --- a/build/Android.common_build.mk +++ b/build/Android.common_build.mk @@ -236,6 +236,9 @@ art_clang_cflags := -fcolor-diagnostics # Warn if switch fallthroughs aren't annotated. art_clang_cflags += -Wimplicit-fallthrough +# Enable float equality warnings. +art_clang_cflags += -Wfloat-equal + ifeq ($(ART_HOST_CLANG),true) ART_HOST_CFLAGS += $(art_clang_cflags) endif diff --git a/compiler/jni/jni_compiler_test.cc b/compiler/jni/jni_compiler_test.cc index a21004c..fd7d350 100644 --- a/compiler/jni/jni_compiler_test.cc +++ b/compiler/jni/jni_compiler_test.cc @@ -365,12 +365,12 @@ void JniCompilerTest::CompileAndRunDoubleDoubleMethodImpl() { EXPECT_EQ(0, gJava_MyClassNatives_fooDD_calls); jdouble result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, 99.0, 10.0); - EXPECT_EQ(99.0 - 10.0, result); + EXPECT_DOUBLE_EQ(99.0 - 10.0, result); EXPECT_EQ(1, gJava_MyClassNatives_fooDD_calls); jdouble a = 3.14159265358979323846; jdouble b = 0.69314718055994530942; result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, a, b); - EXPECT_EQ(a - b, result); + EXPECT_DOUBLE_EQ(a - b, result); EXPECT_EQ(2, gJava_MyClassNatives_fooDD_calls); gJava_MyClassNatives_fooDD_calls = 0; @@ -513,13 +513,13 @@ void JniCompilerTest::CompileAndRunStaticDoubleDoubleMethodImpl() { EXPECT_EQ(0, gJava_MyClassNatives_fooSDD_calls); jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 99.0, 10.0); - EXPECT_EQ(99.0 - 10.0, result); + EXPECT_DOUBLE_EQ(99.0 - 10.0, result); EXPECT_EQ(1, gJava_MyClassNatives_fooSDD_calls); jdouble a = 3.14159265358979323846; jdouble b = 0.69314718055994530942; result = env_->CallStaticDoubleMethod(jklass_, jmethod_, a, b); - EXPECT_EQ(a - b, result); - EXPECT_EQ(2, gJava_MyClassNatives_fooSDD_calls); + EXPECT_DOUBLE_EQ(a - b, result); + EXPECT_DOUBLE_EQ(2, gJava_MyClassNatives_fooSDD_calls); gJava_MyClassNatives_fooSDD_calls = 0; } @@ -539,7 +539,7 @@ void JniCompilerTest::RunStaticLogDoubleMethodImpl() { SetUpForTest(true, "logD", "(D)D", reinterpret_cast<void*>(&Java_MyClassNatives_logD)); jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 2.0); - EXPECT_EQ(log(2.0), result); + EXPECT_DOUBLE_EQ(log(2.0), result); } JNI_TEST(RunStaticLogDoubleMethod) @@ -553,7 +553,7 @@ void JniCompilerTest::RunStaticLogFloatMethodImpl() { SetUpForTest(true, "logF", "(F)F", reinterpret_cast<void*>(&Java_MyClassNatives_logF)); jfloat result = env_->CallStaticFloatMethod(jklass_, jmethod_, 2.0); - EXPECT_EQ(logf(2.0), result); + EXPECT_FLOAT_EQ(logf(2.0), result); } JNI_TEST(RunStaticLogFloatMethod) @@ -1047,11 +1047,11 @@ void JniCompilerTest::CompileAndRunFloatFloatMethodImpl() { jfloat result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, 99.0F, 10.0F); - EXPECT_EQ(99.0F - 10.0F, result); + EXPECT_FLOAT_EQ(99.0F - 10.0F, result); jfloat a = 3.14159F; jfloat b = 0.69314F; result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, a, b); - EXPECT_EQ(a - b, result); + EXPECT_FLOAT_EQ(a - b, result); } JNI_TEST(CompileAndRunFloatFloatMethod) diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index e1f513d..d782aeb 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -90,6 +90,7 @@ static void UsageError(const char* fmt, ...) { va_end(ap); } +static void Usage(const char* fmt, ...) NO_RETURN; static void Usage(const char* fmt, ...) { va_list ap; va_start(ap, fmt); @@ -662,7 +663,7 @@ class WatchDog { Message('W', message); } - static void Fatal(const std::string& message) { + static void Fatal(const std::string& message) NO_RETURN { Message('F', message); exit(1); } diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index fbb36f3..2d165b0 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -644,6 +644,7 @@ static void UsageError(const char* fmt, ...) { va_end(ap); } +static void Usage(const char *fmt, ...) NO_RETURN; static void Usage(const char *fmt, ...) { va_list ap; va_start(ap, fmt); diff --git a/runtime/base/histogram-inl.h b/runtime/base/histogram-inl.h index 4c18ce4..b329a31 100644 --- a/runtime/base/histogram-inl.h +++ b/runtime/base/histogram-inl.h @@ -195,6 +195,11 @@ inline void Histogram<Value>::CreateHistogram(CumulativeData* out_data) const { DCHECK_LE(std::abs(out_data->perc_.back() - 1.0), 0.001); } +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" +#endif + template <class Value> inline double Histogram<Value>::Percentile(double per, const CumulativeData& data) const { DCHECK_GT(data.perc_.size(), 0ull); @@ -235,6 +240,10 @@ inline double Histogram<Value>::Percentile(double per, const CumulativeData& dat return value; } +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + } // namespace art #endif // ART_RUNTIME_BASE_HISTOGRAM_INL_H_ diff --git a/runtime/base/histogram_test.cc b/runtime/base/histogram_test.cc index 454f2ab..7aa5f90 100644 --- a/runtime/base/histogram_test.cc +++ b/runtime/base/histogram_test.cc @@ -41,14 +41,14 @@ TEST(Histtest, MeanTest) { hist->AddValue(static_cast<uint64_t>(50)); } mean = hist->Mean(); - EXPECT_EQ(mean, 50); + EXPECT_DOUBLE_EQ(mean, 50.0); hist->Reset(); hist->AddValue(9); hist->AddValue(17); hist->AddValue(28); hist->AddValue(28); mean = hist->Mean(); - EXPECT_EQ(20.5, mean); + EXPECT_DOUBLE_EQ(20.5, mean); } TEST(Histtest, VarianceTest) { @@ -60,7 +60,7 @@ TEST(Histtest, VarianceTest) { hist->AddValue(28); hist->AddValue(28); variance = hist->Variance(); - EXPECT_EQ(64.25, variance); + EXPECT_DOUBLE_EQ(64.25, variance); } TEST(Histtest, Percentile) { @@ -236,7 +236,7 @@ TEST(Histtest, CappingPercentiles) { } hist->CreateHistogram(&data); per_995 = hist->Percentile(0.995, data); - EXPECT_EQ(per_995, 0); + EXPECT_DOUBLE_EQ(per_995, 0.0); hist->Reset(); for (size_t idx = 0; idx < 200; idx++) { for (uint64_t val = 1ull; val <= 4ull; val++) { @@ -246,8 +246,8 @@ TEST(Histtest, CappingPercentiles) { hist->CreateHistogram(&data); per_005 = hist->Percentile(0.005, data); per_995 = hist->Percentile(0.995, data); - EXPECT_EQ(1, per_005); - EXPECT_EQ(4, per_995); + EXPECT_DOUBLE_EQ(1.0, per_005); + EXPECT_DOUBLE_EQ(4.0, per_995); } TEST(Histtest, SpikyValues) { diff --git a/runtime/base/macros.h b/runtime/base/macros.h index f5a38bb..bbe0f5a 100644 --- a/runtime/base/macros.h +++ b/runtime/base/macros.h @@ -177,6 +177,7 @@ char (&ArraySizeHelper(T (&array)[N]))[N]; #define PURE __attribute__ ((__pure__)) #define WARN_UNUSED __attribute__((warn_unused_result)) +#define NO_RETURN __attribute__((noreturn)) template<typename T> void UNUSED(const T&) {} #define UNREACHABLE __builtin_unreachable diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index e990181..88e6265 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -907,12 +907,12 @@ TEST_F(ClassLinkerTest, StaticFields) { mirror::ArtField* s6 = mirror::Class::FindStaticField(soa.Self(), statics, "s6", "F"); EXPECT_EQ(s6->GetTypeAsPrimitiveType(), Primitive::kPrimFloat); - EXPECT_EQ(0.5, s6->GetFloat(statics.Get())); + EXPECT_DOUBLE_EQ(0.5, s6->GetFloat(statics.Get())); s6->SetFloat<false>(statics.Get(), 0.75); mirror::ArtField* s7 = mirror::Class::FindStaticField(soa.Self(), statics, "s7", "D"); EXPECT_EQ(s7->GetTypeAsPrimitiveType(), Primitive::kPrimDouble); - EXPECT_EQ(16777217, s7->GetDouble(statics.Get())); + EXPECT_DOUBLE_EQ(16777217.0, s7->GetDouble(statics.Get())); s7->SetDouble<false>(statics.Get(), 16777219); mirror::ArtField* s8 = mirror::Class::FindStaticField(soa.Self(), statics, "s8", @@ -930,8 +930,8 @@ TEST_F(ClassLinkerTest, StaticFields) { EXPECT_EQ(-535, s3->GetShort(statics.Get())); EXPECT_EQ(2000000001, s4->GetInt(statics.Get())); EXPECT_EQ(INT64_C(0x34567890abcdef12), s5->GetLong(statics.Get())); - EXPECT_EQ(0.75, s6->GetFloat(statics.Get())); - EXPECT_EQ(16777219, s7->GetDouble(statics.Get())); + EXPECT_FLOAT_EQ(0.75, s6->GetFloat(statics.Get())); + EXPECT_DOUBLE_EQ(16777219.0, s7->GetDouble(statics.Get())); EXPECT_TRUE(s8->GetObject(statics.Get())->AsString()->Equals("robot")); } diff --git a/runtime/entrypoints/quick/quick_math_entrypoints.cc b/runtime/entrypoints/quick/quick_math_entrypoints.cc index 014aad3..1c658b7 100644 --- a/runtime/entrypoints/quick/quick_math_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_math_entrypoints.cc @@ -18,6 +18,11 @@ namespace art { +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" +#endif + int CmplFloat(float a, float b) { if (a == b) { return 0; @@ -62,6 +67,10 @@ int CmplDouble(double a, double b) { return -1; } +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + extern "C" int64_t artLmul(int64_t a, int64_t b) { return a * b; } diff --git a/runtime/interpreter/interpreter_goto_table_impl.cc b/runtime/interpreter/interpreter_goto_table_impl.cc index db7c452..88d6544 100644 --- a/runtime/interpreter/interpreter_goto_table_impl.cc +++ b/runtime/interpreter/interpreter_goto_table_impl.cc @@ -662,6 +662,11 @@ JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh, const DexFile::CodeItem* } HANDLE_INSTRUCTION_END(); +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" +#endif + HANDLE_INSTRUCTION_START(CMPL_FLOAT) { float val1 = shadow_frame.GetVRegFloat(inst->VRegB_23x()); float val2 = shadow_frame.GetVRegFloat(inst->VRegC_23x()); @@ -726,6 +731,10 @@ JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh, const DexFile::CodeItem* } HANDLE_INSTRUCTION_END(); +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + HANDLE_INSTRUCTION_START(CMP_LONG) { int64_t val1 = shadow_frame.GetVRegLong(inst->VRegB_23x()); int64_t val2 = shadow_frame.GetVRegLong(inst->VRegC_23x()); diff --git a/runtime/interpreter/interpreter_switch_impl.cc b/runtime/interpreter/interpreter_switch_impl.cc index fe0af27..14e8a52 100644 --- a/runtime/interpreter/interpreter_switch_impl.cc +++ b/runtime/interpreter/interpreter_switch_impl.cc @@ -562,6 +562,12 @@ JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh, const DexFile::CodeItem inst = inst->RelativeAt(offset); break; } + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" +#endif + case Instruction::CMPL_FLOAT: { PREAMBLE(); float val1 = shadow_frame.GetVRegFloat(inst->VRegB_23x()); @@ -627,6 +633,11 @@ JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh, const DexFile::CodeItem inst = inst->Next_2xx(); break; } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + case Instruction::CMP_LONG: { PREAMBLE(); int64_t val1 = shadow_frame.GetVRegLong(inst->VRegB_23x()); diff --git a/runtime/jni_internal_test.cc b/runtime/jni_internal_test.cc index 20d031c..cab907c 100644 --- a/runtime/jni_internal_test.cc +++ b/runtime/jni_internal_test.cc @@ -1527,14 +1527,14 @@ TEST_F(JniInternalTest, GetObjectArrayElement_SetObjectArrayElement) { EXPECT_TRUE(vm_->SetCheckJniEnabled(old_check_jni)); } -#define EXPECT_STATIC_PRIMITIVE_FIELD(type, field_name, sig, value1, value2) \ +#define EXPECT_STATIC_PRIMITIVE_FIELD(expect_eq, type, field_name, sig, value1, value2) \ do { \ jfieldID fid = env_->GetStaticFieldID(c, field_name, sig); \ EXPECT_NE(fid, nullptr); \ env_->SetStatic ## type ## Field(c, fid, value1); \ - EXPECT_EQ(value1, env_->GetStatic ## type ## Field(c, fid)); \ + expect_eq(value1, env_->GetStatic ## type ## Field(c, fid)); \ env_->SetStatic ## type ## Field(c, fid, value2); \ - EXPECT_EQ(value2, env_->GetStatic ## type ## Field(c, fid)); \ + expect_eq(value2, env_->GetStatic ## type ## Field(c, fid)); \ \ bool old_check_jni = vm_->SetCheckJniEnabled(false); \ { \ @@ -1560,14 +1560,14 @@ TEST_F(JniInternalTest, GetObjectArrayElement_SetObjectArrayElement) { EXPECT_TRUE(vm_->SetCheckJniEnabled(old_check_jni)); \ } while (false) -#define EXPECT_PRIMITIVE_FIELD(instance, type, field_name, sig, value1, value2) \ +#define EXPECT_PRIMITIVE_FIELD(expect_eq, instance, type, field_name, sig, value1, value2) \ do { \ jfieldID fid = env_->GetFieldID(c, field_name, sig); \ EXPECT_NE(fid, nullptr); \ env_->Set ## type ## Field(instance, fid, value1); \ - EXPECT_EQ(value1, env_->Get ## type ## Field(instance, fid)); \ + expect_eq(value1, env_->Get ## type ## Field(instance, fid)); \ env_->Set ## type ## Field(instance, fid, value2); \ - EXPECT_EQ(value2, env_->Get ## type ## Field(instance, fid)); \ + expect_eq(value2, env_->Get ## type ## Field(instance, fid)); \ \ bool old_check_jni = vm_->SetCheckJniEnabled(false); \ CheckJniAbortCatcher jni_abort_catcher; \ @@ -1604,23 +1604,23 @@ TEST_F(JniInternalTest, GetPrimitiveField_SetPrimitiveField) { jobject o = env_->AllocObject(c); ASSERT_NE(o, nullptr); - EXPECT_STATIC_PRIMITIVE_FIELD(Boolean, "sZ", "Z", JNI_TRUE, JNI_FALSE); - EXPECT_STATIC_PRIMITIVE_FIELD(Byte, "sB", "B", 1, 2); - EXPECT_STATIC_PRIMITIVE_FIELD(Char, "sC", "C", 'a', 'b'); - EXPECT_STATIC_PRIMITIVE_FIELD(Double, "sD", "D", 1.0, 2.0); - EXPECT_STATIC_PRIMITIVE_FIELD(Float, "sF", "F", 1.0, 2.0); - EXPECT_STATIC_PRIMITIVE_FIELD(Int, "sI", "I", 1, 2); - EXPECT_STATIC_PRIMITIVE_FIELD(Long, "sJ", "J", 1, 2); - EXPECT_STATIC_PRIMITIVE_FIELD(Short, "sS", "S", 1, 2); - - EXPECT_PRIMITIVE_FIELD(o, Boolean, "iZ", "Z", JNI_TRUE, JNI_FALSE); - EXPECT_PRIMITIVE_FIELD(o, Byte, "iB", "B", 1, 2); - EXPECT_PRIMITIVE_FIELD(o, Char, "iC", "C", 'a', 'b'); - EXPECT_PRIMITIVE_FIELD(o, Double, "iD", "D", 1.0, 2.0); - EXPECT_PRIMITIVE_FIELD(o, Float, "iF", "F", 1.0, 2.0); - EXPECT_PRIMITIVE_FIELD(o, Int, "iI", "I", 1, 2); - EXPECT_PRIMITIVE_FIELD(o, Long, "iJ", "J", 1, 2); - EXPECT_PRIMITIVE_FIELD(o, Short, "iS", "S", 1, 2); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_EQ, Boolean, "sZ", "Z", JNI_TRUE, JNI_FALSE); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_EQ, Byte, "sB", "B", 1, 2); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_EQ, Char, "sC", "C", 'a', 'b'); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_DOUBLE_EQ, Double, "sD", "D", 1.0, 2.0); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_FLOAT_EQ, Float, "sF", "F", 1.0, 2.0); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_EQ, Int, "sI", "I", 1, 2); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_EQ, Long, "sJ", "J", 1, 2); + EXPECT_STATIC_PRIMITIVE_FIELD(EXPECT_EQ, Short, "sS", "S", 1, 2); + + EXPECT_PRIMITIVE_FIELD(EXPECT_EQ, o, Boolean, "iZ", "Z", JNI_TRUE, JNI_FALSE); + EXPECT_PRIMITIVE_FIELD(EXPECT_EQ, o, Byte, "iB", "B", 1, 2); + EXPECT_PRIMITIVE_FIELD(EXPECT_EQ, o, Char, "iC", "C", 'a', 'b'); + EXPECT_PRIMITIVE_FIELD(EXPECT_DOUBLE_EQ, o, Double, "iD", "D", 1.0, 2.0); + EXPECT_PRIMITIVE_FIELD(EXPECT_FLOAT_EQ, o, Float, "iF", "F", 1.0, 2.0); + EXPECT_PRIMITIVE_FIELD(EXPECT_EQ, o, Int, "iI", "I", 1, 2); + EXPECT_PRIMITIVE_FIELD(EXPECT_EQ, o, Long, "iJ", "J", 1, 2); + EXPECT_PRIMITIVE_FIELD(EXPECT_EQ, o, Short, "iS", "S", 1, 2); } TEST_F(JniInternalTest, GetObjectField_SetObjectField) { diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc index 1aeba74..a2a0626 100644 --- a/runtime/mirror/object_test.cc +++ b/runtime/mirror/object_test.cc @@ -248,12 +248,6 @@ TEST_F(ObjectTest, PrimitiveArray_Byte_Alloc) { TEST_F(ObjectTest, PrimitiveArray_Char_Alloc) { TestPrimitiveArray<CharArray>(class_linker_); } -TEST_F(ObjectTest, PrimitiveArray_Double_Alloc) { - TestPrimitiveArray<DoubleArray>(class_linker_); -} -TEST_F(ObjectTest, PrimitiveArray_Float_Alloc) { - TestPrimitiveArray<FloatArray>(class_linker_); -} TEST_F(ObjectTest, PrimitiveArray_Int_Alloc) { TestPrimitiveArray<IntArray>(class_linker_); } @@ -264,6 +258,67 @@ TEST_F(ObjectTest, PrimitiveArray_Short_Alloc) { TestPrimitiveArray<ShortArray>(class_linker_); } +TEST_F(ObjectTest, PrimitiveArray_Double_Alloc) { + typedef DoubleArray ArrayT; + ScopedObjectAccess soa(Thread::Current()); + typedef typename ArrayT::ElementType T; + + ArrayT* a = ArrayT::Alloc(soa.Self(), 2); + EXPECT_EQ(2, a->GetLength()); + EXPECT_DOUBLE_EQ(0, a->Get(0)); + EXPECT_DOUBLE_EQ(0, a->Get(1)); + a->Set(0, T(123)); + EXPECT_DOUBLE_EQ(T(123), a->Get(0)); + EXPECT_DOUBLE_EQ(0, a->Get(1)); + a->Set(1, T(321)); + EXPECT_DOUBLE_EQ(T(123), a->Get(0)); + EXPECT_DOUBLE_EQ(T(321), a->Get(1)); + + Class* aioobe = class_linker_->FindSystemClass(soa.Self(), + "Ljava/lang/ArrayIndexOutOfBoundsException;"); + + EXPECT_DOUBLE_EQ(0, a->Get(-1)); + EXPECT_TRUE(soa.Self()->IsExceptionPending()); + EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); + soa.Self()->ClearException(); + + EXPECT_DOUBLE_EQ(0, a->Get(2)); + EXPECT_TRUE(soa.Self()->IsExceptionPending()); + EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); + soa.Self()->ClearException(); +} + +TEST_F(ObjectTest, PrimitiveArray_Float_Alloc) { + typedef FloatArray ArrayT; + ScopedObjectAccess soa(Thread::Current()); + typedef typename ArrayT::ElementType T; + + ArrayT* a = ArrayT::Alloc(soa.Self(), 2); + EXPECT_FLOAT_EQ(2, a->GetLength()); + EXPECT_FLOAT_EQ(0, a->Get(0)); + EXPECT_FLOAT_EQ(0, a->Get(1)); + a->Set(0, T(123)); + EXPECT_FLOAT_EQ(T(123), a->Get(0)); + EXPECT_FLOAT_EQ(0, a->Get(1)); + a->Set(1, T(321)); + EXPECT_FLOAT_EQ(T(123), a->Get(0)); + EXPECT_FLOAT_EQ(T(321), a->Get(1)); + + Class* aioobe = class_linker_->FindSystemClass(soa.Self(), + "Ljava/lang/ArrayIndexOutOfBoundsException;"); + + EXPECT_FLOAT_EQ(0, a->Get(-1)); + EXPECT_TRUE(soa.Self()->IsExceptionPending()); + EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); + soa.Self()->ClearException(); + + EXPECT_FLOAT_EQ(0, a->Get(2)); + EXPECT_TRUE(soa.Self()->IsExceptionPending()); + EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); + soa.Self()->ClearException(); +} + + TEST_F(ObjectTest, CheckAndAllocArrayFromCode) { // pretend we are trying to call 'new char[3]' from String.toCharArray ScopedObjectAccess soa(Thread::Current()); diff --git a/runtime/native/java_lang_Runtime.cc b/runtime/native/java_lang_Runtime.cc index a85eec7..62ca14d 100644 --- a/runtime/native/java_lang_Runtime.cc +++ b/runtime/native/java_lang_Runtime.cc @@ -37,6 +37,7 @@ static void Runtime_gc(JNIEnv*, jclass) { Runtime::Current()->GetHeap()->CollectGarbage(false); } +static void Runtime_nativeExit(JNIEnv*, jclass, jint status) NO_RETURN; static void Runtime_nativeExit(JNIEnv*, jclass, jint status) { LOG(INFO) << "System.exit called, status: " << status; Runtime::Current()->CallExitHook(status); diff --git a/runtime/parsed_options_test.cc b/runtime/parsed_options_test.cc index 5154d69..61481b1 100644 --- a/runtime/parsed_options_test.cc +++ b/runtime/parsed_options_test.cc @@ -64,7 +64,7 @@ TEST_F(ParsedOptionsTest, ParsedOptions) { EXPECT_EQ(2048U, parsed->heap_initial_size_); EXPECT_EQ(4 * KB, parsed->heap_maximum_size_); EXPECT_EQ(1 * MB, parsed->stack_size_); - EXPECT_EQ(0.75, parsed->heap_target_utilization_); + EXPECT_DOUBLE_EQ(0.75, parsed->heap_target_utilization_); EXPECT_TRUE(test_vfprintf == parsed->hook_vfprintf_); EXPECT_TRUE(test_exit == parsed->hook_exit_); EXPECT_TRUE(test_abort == parsed->hook_abort_); diff --git a/runtime/reflection_test.cc b/runtime/reflection_test.cc index 75211e0..f8e0f47 100644 --- a/runtime/reflection_test.cc +++ b/runtime/reflection_test.cc @@ -193,19 +193,19 @@ class ReflectionTest : public CommonCompilerTest { args[0].d = 0.0; JValue result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(0.0, result.GetD()); + EXPECT_DOUBLE_EQ(0.0, result.GetD()); args[0].d = -1.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(-1.0, result.GetD()); + EXPECT_DOUBLE_EQ(-1.0, result.GetD()); args[0].d = DBL_MAX; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(DBL_MAX, result.GetD()); + EXPECT_DOUBLE_EQ(DBL_MAX, result.GetD()); args[0].d = DBL_MIN; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(DBL_MIN, result.GetD()); + EXPECT_DOUBLE_EQ(DBL_MIN, result.GetD()); } void InvokeSumIntIntMethod(bool is_static) { @@ -375,27 +375,27 @@ class ReflectionTest : public CommonCompilerTest { args[0].d = 0.0; args[1].d = 0.0; JValue result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(0.0, result.GetD()); + EXPECT_DOUBLE_EQ(0.0, result.GetD()); args[0].d = 1.0; args[1].d = 2.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(3.0, result.GetD()); + EXPECT_DOUBLE_EQ(3.0, result.GetD()); args[0].d = 1.0; args[1].d = -2.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(-1.0, result.GetD()); + EXPECT_DOUBLE_EQ(-1.0, result.GetD()); args[0].d = DBL_MAX; args[1].d = DBL_MIN; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(1.7976931348623157e308, result.GetD()); + EXPECT_DOUBLE_EQ(1.7976931348623157e308, result.GetD()); args[0].d = DBL_MAX; args[1].d = DBL_MAX; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(INFINITY, result.GetD()); + EXPECT_DOUBLE_EQ(INFINITY, result.GetD()); } void InvokeSumDoubleDoubleDoubleMethod(bool is_static) { @@ -409,19 +409,19 @@ class ReflectionTest : public CommonCompilerTest { args[1].d = 0.0; args[2].d = 0.0; JValue result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(0.0, result.GetD()); + EXPECT_DOUBLE_EQ(0.0, result.GetD()); args[0].d = 1.0; args[1].d = 2.0; args[2].d = 3.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(6.0, result.GetD()); + EXPECT_DOUBLE_EQ(6.0, result.GetD()); args[0].d = 1.0; args[1].d = -2.0; args[2].d = 3.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(2.0, result.GetD()); + EXPECT_DOUBLE_EQ(2.0, result.GetD()); } void InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static) { @@ -436,21 +436,21 @@ class ReflectionTest : public CommonCompilerTest { args[2].d = 0.0; args[3].d = 0.0; JValue result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(0.0, result.GetD()); + EXPECT_DOUBLE_EQ(0.0, result.GetD()); args[0].d = 1.0; args[1].d = 2.0; args[2].d = 3.0; args[3].d = 4.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(10.0, result.GetD()); + EXPECT_DOUBLE_EQ(10.0, result.GetD()); args[0].d = 1.0; args[1].d = -2.0; args[2].d = 3.0; args[3].d = -4.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(-2.0, result.GetD()); + EXPECT_DOUBLE_EQ(-2.0, result.GetD()); } void InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static) { @@ -466,7 +466,7 @@ class ReflectionTest : public CommonCompilerTest { args[3].d = 0.0; args[4].d = 0.0; JValue result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(0.0, result.GetD()); + EXPECT_DOUBLE_EQ(0.0, result.GetD()); args[0].d = 1.0; args[1].d = 2.0; @@ -474,7 +474,7 @@ class ReflectionTest : public CommonCompilerTest { args[3].d = 4.0; args[4].d = 5.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(15.0, result.GetD()); + EXPECT_DOUBLE_EQ(15.0, result.GetD()); args[0].d = 1.0; args[1].d = -2.0; @@ -482,7 +482,7 @@ class ReflectionTest : public CommonCompilerTest { args[3].d = -4.0; args[4].d = 5.0; result = InvokeWithJValues(soa, receiver, soa.EncodeMethod(method), args); - EXPECT_EQ(3.0, result.GetD()); + EXPECT_DOUBLE_EQ(3.0, result.GetD()); } JavaVMExt* vm_; diff --git a/runtime/runtime.h b/runtime/runtime.h index 1a6c6e0..30dabe7 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -180,7 +180,7 @@ class Runtime { // This isn't marked ((noreturn)) because then gcc will merge multiple calls // in a single function together. This reduces code size slightly, but means // that the native stack trace we get may point at the wrong call site. - static void Abort() LOCKS_EXCLUDED(Locks::abort_lock_); + static void Abort() NO_RETURN LOCKS_EXCLUDED(Locks::abort_lock_); // Returns the "main" ThreadGroup, used when attaching user threads. jobject GetMainThreadGroup() const; diff --git a/runtime/transaction_test.cc b/runtime/transaction_test.cc index a14889c..8c4b90d 100644 --- a/runtime/transaction_test.cc +++ b/runtime/transaction_test.cc @@ -147,12 +147,12 @@ TEST_F(TransactionTest, StaticFieldsTest) { mirror::ArtField* floatField = h_klass->FindDeclaredStaticField("floatField", "F"); ASSERT_TRUE(floatField != nullptr); ASSERT_EQ(floatField->GetTypeAsPrimitiveType(), Primitive::kPrimFloat); - ASSERT_EQ(floatField->GetFloat(h_klass.Get()), static_cast<float>(0.0f)); + ASSERT_FLOAT_EQ(floatField->GetFloat(h_klass.Get()), static_cast<float>(0.0f)); mirror::ArtField* doubleField = h_klass->FindDeclaredStaticField("doubleField", "D"); ASSERT_TRUE(doubleField != nullptr); ASSERT_EQ(doubleField->GetTypeAsPrimitiveType(), Primitive::kPrimDouble); - ASSERT_EQ(doubleField->GetDouble(h_klass.Get()), static_cast<double>(0.0)); + ASSERT_DOUBLE_EQ(doubleField->GetDouble(h_klass.Get()), static_cast<double>(0.0)); mirror::ArtField* objectField = h_klass->FindDeclaredStaticField("objectField", "Ljava/lang/Object;"); @@ -190,8 +190,8 @@ TEST_F(TransactionTest, StaticFieldsTest) { EXPECT_EQ(shortField->GetShort(h_klass.Get()), 0); EXPECT_EQ(intField->GetInt(h_klass.Get()), 0); EXPECT_EQ(longField->GetLong(h_klass.Get()), static_cast<int64_t>(0)); - EXPECT_EQ(floatField->GetFloat(h_klass.Get()), static_cast<float>(0.0f)); - EXPECT_EQ(doubleField->GetDouble(h_klass.Get()), static_cast<double>(0.0)); + EXPECT_FLOAT_EQ(floatField->GetFloat(h_klass.Get()), static_cast<float>(0.0f)); + EXPECT_DOUBLE_EQ(doubleField->GetDouble(h_klass.Get()), static_cast<double>(0.0)); EXPECT_EQ(objectField->GetObject(h_klass.Get()), nullptr); } @@ -246,12 +246,12 @@ TEST_F(TransactionTest, InstanceFieldsTest) { mirror::ArtField* floatField = h_klass->FindDeclaredInstanceField("floatField", "F"); ASSERT_TRUE(floatField != nullptr); ASSERT_EQ(floatField->GetTypeAsPrimitiveType(), Primitive::kPrimFloat); - ASSERT_EQ(floatField->GetFloat(h_instance.Get()), static_cast<float>(0.0f)); + ASSERT_FLOAT_EQ(floatField->GetFloat(h_instance.Get()), static_cast<float>(0.0f)); mirror::ArtField* doubleField = h_klass->FindDeclaredInstanceField("doubleField", "D"); ASSERT_TRUE(doubleField != nullptr); ASSERT_EQ(doubleField->GetTypeAsPrimitiveType(), Primitive::kPrimDouble); - ASSERT_EQ(doubleField->GetDouble(h_instance.Get()), static_cast<double>(0.0)); + ASSERT_DOUBLE_EQ(doubleField->GetDouble(h_instance.Get()), static_cast<double>(0.0)); mirror::ArtField* objectField = h_klass->FindDeclaredInstanceField("objectField", "Ljava/lang/Object;"); @@ -289,8 +289,8 @@ TEST_F(TransactionTest, InstanceFieldsTest) { EXPECT_EQ(shortField->GetShort(h_instance.Get()), 0); EXPECT_EQ(intField->GetInt(h_instance.Get()), 0); EXPECT_EQ(longField->GetLong(h_instance.Get()), static_cast<int64_t>(0)); - EXPECT_EQ(floatField->GetFloat(h_instance.Get()), static_cast<float>(0.0f)); - EXPECT_EQ(doubleField->GetDouble(h_instance.Get()), static_cast<double>(0.0)); + EXPECT_FLOAT_EQ(floatField->GetFloat(h_instance.Get()), static_cast<float>(0.0f)); + EXPECT_DOUBLE_EQ(doubleField->GetDouble(h_instance.Get()), static_cast<double>(0.0)); EXPECT_EQ(objectField->GetObject(h_instance.Get()), nullptr); } @@ -356,14 +356,14 @@ TEST_F(TransactionTest, StaticArrayFieldsTest) { mirror::FloatArray* floatArray = floatArrayField->GetObject(h_klass.Get())->AsFloatArray(); ASSERT_TRUE(floatArray != nullptr); ASSERT_EQ(floatArray->GetLength(), 1); - ASSERT_EQ(floatArray->GetWithoutChecks(0), static_cast<float>(0.0f)); + ASSERT_FLOAT_EQ(floatArray->GetWithoutChecks(0), static_cast<float>(0.0f)); mirror::ArtField* doubleArrayField = h_klass->FindDeclaredStaticField("doubleArrayField", "[D"); ASSERT_TRUE(doubleArrayField != nullptr); mirror::DoubleArray* doubleArray = doubleArrayField->GetObject(h_klass.Get())->AsDoubleArray(); ASSERT_TRUE(doubleArray != nullptr); ASSERT_EQ(doubleArray->GetLength(), 1); - ASSERT_EQ(doubleArray->GetWithoutChecks(0), static_cast<double>(0.0f)); + ASSERT_DOUBLE_EQ(doubleArray->GetWithoutChecks(0), static_cast<double>(0.0f)); mirror::ArtField* objectArrayField = h_klass->FindDeclaredStaticField("objectArrayField", "[Ljava/lang/Object;"); @@ -404,8 +404,8 @@ TEST_F(TransactionTest, StaticArrayFieldsTest) { EXPECT_EQ(shortArray->GetWithoutChecks(0), 0); EXPECT_EQ(intArray->GetWithoutChecks(0), 0); EXPECT_EQ(longArray->GetWithoutChecks(0), static_cast<int64_t>(0)); - EXPECT_EQ(floatArray->GetWithoutChecks(0), static_cast<float>(0.0f)); - EXPECT_EQ(doubleArray->GetWithoutChecks(0), static_cast<double>(0.0f)); + EXPECT_FLOAT_EQ(floatArray->GetWithoutChecks(0), static_cast<float>(0.0f)); + EXPECT_DOUBLE_EQ(doubleArray->GetWithoutChecks(0), static_cast<double>(0.0f)); EXPECT_EQ(objectArray->GetWithoutChecks(0), nullptr); } |