From a8908ef14cf2d2e0d05e41e319da5d6909325ae2 Mon Sep 17 00:00:00 2001 From: Sergio Giro Date: Mon, 11 Apr 2016 20:49:20 +0100 Subject: [PATCH] unstarted_runtime: add cutout for Math.floor Needed in order to make BouncyCastleProvider initializable in compile time Bug: 28108158 Change-Id: If445a0b3e4a072d7139e2506c2a5910312b302d1 --- runtime/interpreter/unstarted_runtime.cc | 20 ++++++++++++++++---- runtime/interpreter/unstarted_runtime_list.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc index 4615ec9aa..80ffedcaa 100644 --- a/runtime/interpreter/unstarted_runtime.cc +++ b/runtime/interpreter/unstarted_runtime.cc @@ -524,9 +524,7 @@ void UnstartedRuntime::UnstartedThreadLocalGet( } } -void UnstartedRuntime::UnstartedMathCeil( - Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) { - double in = shadow_frame->GetVRegDouble(arg_offset); +static double ComputeCeil(double in) { double out; // Special cases: // 1) NaN, infinity, +0, -0 -> out := in. All are guaranteed by cmath. @@ -536,7 +534,21 @@ void UnstartedRuntime::UnstartedMathCeil( } else { out = ceil(in); } - result->SetD(out); + return out; +} + +void UnstartedRuntime::UnstartedMathCeil( + Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) { + double in = shadow_frame->GetVRegDouble(arg_offset); + result->SetD(ComputeCeil(in)); +} + +void UnstartedRuntime::UnstartedMathFloor( + Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) { + double in = shadow_frame->GetVRegDouble(arg_offset); + // From the JavaDocs: + // "Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x)." + result->SetD(-ComputeCeil(-in)); } void UnstartedRuntime::UnstartedObjectHashCode( diff --git a/runtime/interpreter/unstarted_runtime_list.h b/runtime/interpreter/unstarted_runtime_list.h index a3ed5581f..331270113 100644 --- a/runtime/interpreter/unstarted_runtime_list.h +++ b/runtime/interpreter/unstarted_runtime_list.h @@ -36,6 +36,7 @@ V(SystemGetSecurityManager, "java.lang.SecurityManager java.lang.System.getSecurityManager()") \ V(ThreadLocalGet, "java.lang.Object java.lang.ThreadLocal.get()") \ V(MathCeil, "double java.lang.Math.ceil(double)") \ + V(MathFloor, "double java.lang.Math.floor(double)") \ V(ObjectHashCode, "int java.lang.Object.hashCode()") \ V(DoubleDoubleToRawLongBits, "long java.lang.Double.doubleToRawLongBits(double)") \ V(DexCacheGetDexNative, "com.android.dex.Dex java.lang.DexCache.getDexNative()") \ -- 2.11.0