diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2019-04-16 22:19:20 +0000 |
---|---|---|
committer | android-build-prod (mdb) <android-build-team-robot@google.com> | 2019-04-16 22:19:20 +0000 |
commit | 9f4f08954fb88da9fdad0693fc970bfd6c7c2c66 (patch) | |
tree | 9159ef66bd6dd746709e3627a186e1c6cfec61d8 | |
parent | 9f3c187ee02b150e95530c64579798ea1a6058ab (diff) | |
parent | 3e8c12aba8b34a9f00453569a0693b922f387f13 (diff) | |
download | crcalc-9f4f08954fb88da9fdad0693fc970bfd6c7c2c66.tar.gz |
Snap for 5475808 from 3e8c12aba8b34a9f00453569a0693b922f387f13 to sdk-release
Change-Id: I4235020a56b9a5a4a43257274846d462fc8ec051
-rw-r--r-- | Android.bp | 26 | ||||
-rw-r--r-- | Android.mk | 32 | ||||
-rw-r--r-- | src/com/hp/creals/CR.java | 36 | ||||
-rw-r--r-- | tests/Android.bp | 26 | ||||
-rw-r--r-- | tests/Android.mk | 30 |
5 files changed, 77 insertions, 73 deletions
diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..3020f7b --- /dev/null +++ b/Android.bp @@ -0,0 +1,26 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Other files in this directory carry a different license. + +// build the client library +//------------------------------- +java_library { + name: "cr", + + srcs: ["src/**/*.java"], + + sdk_version: "19", + +} diff --git a/Android.mk b/Android.mk deleted file mode 100644 index b78e9e1..0000000 --- a/Android.mk +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2014 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Other files in this directory carry a different license. - -LOCAL_PATH := $(call my-dir) - -# build the client library -#------------------------------- -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -LOCAL_MODULE := cr -LOCAL_MODULE_TAGS := optional -LOCAL_SDK_VERSION := 19 - -include $(BUILD_STATIC_JAVA_LIBRARY) - -include $(call all-makefiles-under,$(LOCAL_PATH)) - diff --git a/src/com/hp/creals/CR.java b/src/com/hp/creals/CR.java index 35ab0dc..c5a1c41 100644 --- a/src/com/hp/creals/CR.java +++ b/src/com/hp/creals/CR.java @@ -114,6 +114,8 @@ // Fix a couple of unused variable bugs. Notably selector_sign was // accidentally locally redeclared. (This turns out to be safe but useless.) // hboehm@google.com 11/20/2018. +// Fix an exception-safety issue in gl_pi_CR.approximate. +// hboehm@google.com 3/3/2019. package com.hp.creals; @@ -1577,6 +1579,11 @@ class gl_pi_CR extends slow_CR { private static CR SQRT_HALF = new sqrt_CR(ONE.shiftRight(1)); protected BigInteger approximate(int p) { + // Get us back into a consistent state if the last computation + // was interrupted after pushing onto b_prec. + if (b_prec.size() > b_val.size()) { + b_prec.remove(b_prec.size() - 1); + } // Rough approximations are easy. if (p >= 0) return scale(BigInteger.valueOf(3), -p); // We need roughly log2(p) iterations. Each iteration should @@ -1595,28 +1602,35 @@ class gl_pi_CR extends slow_CR { // Current values correspond to n, next_ values to n + 1 // b_prec.size() == b_val.size() >= n + 1 final BigInteger next_a = a.add(b).shiftRight(1); + final BigInteger next_b; final BigInteger a_diff = a.subtract(next_a); - CR next_b_as_CR; final BigInteger b_prod = a.multiply(b).shiftRight(-eval_prec); - // We the compute square root approximations using a nested + // We compute square root approximations using a nested // temporary CR computation, to avoid implementing BigInteger // square roots separately. final CR b_prod_as_CR = CR.valueOf(b_prod).shiftRight(-eval_prec); if (b_prec.size() == n + 1) { - // Need an n+1st slot. - b_prec.add(null); - b_val.add(null); - next_b_as_CR = b_prod_as_CR.sqrt(); + // Add an n+1st slot. + // Take care to make this exception-safe; b_prec and b_val + // must remain consistent, even if we are interrupted, or run + // out of memory. It's OK to just push on b_prec in that case. + final CR next_b_as_CR = b_prod_as_CR.sqrt(); + next_b = next_b_as_CR.get_appr(eval_prec); + final BigInteger scaled_next_b = scale(next_b, -extra_eval_prec); + b_prec.add(p); + b_val.add(scaled_next_b); } else { // Reuse previous approximation to reduce sqrt iterations, // hopefully to one. - next_b_as_CR = new sqrt_CR(b_prod_as_CR, b_prec.get(n + 1), - b_val.get(n + 1)); + final CR next_b_as_CR = + new sqrt_CR(b_prod_as_CR, + b_prec.get(n + 1), b_val.get(n + 1)); + next_b = next_b_as_CR.get_appr(eval_prec); + // We assume that set() doesn't throw for any reason. + b_prec.set(n + 1, p); + b_val.set(n + 1, scale(next_b, -extra_eval_prec)); } // b_prec.size() == b_val.size() >= n + 2 - final BigInteger next_b = next_b_as_CR.get_appr(eval_prec); - b_prec.set(n + 1, Integer.valueOf(p)); - b_val.set(n + 1, scale(next_b, -extra_eval_prec)); final BigInteger next_t = t.subtract(a_diff.multiply(a_diff) .shiftLeft(n + eval_prec)); // shift dist. usually neg. diff --git a/tests/Android.bp b/tests/Android.bp new file mode 100644 index 0000000..c8e308c --- /dev/null +++ b/tests/Android.bp @@ -0,0 +1,26 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Other files in this directory carry a different license. + +// build the test apk +//------------------------------- +android_test { + name: "CRTests", + sdk_version: "19", + srcs: [ + "src/**/*.java", + ], + static_libs: ["cr"], +} diff --git a/tests/Android.mk b/tests/Android.mk deleted file mode 100644 index 441752e..0000000 --- a/tests/Android.mk +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 2015 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Other files in this directory carry a different license. - -LOCAL_PATH := $(call my-dir) - -# build the test apk -#------------------------------- -include $(CLEAR_VARS) - -LOCAL_PACKAGE_NAME := CRTests -LOCAL_SDK_VERSION := 19 -LOCAL_MODULE_TAGS := tests -LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-java-files-under, ../src) -# Empirically, LOCAL_INSTRUMENTATION_FOR doesn't work, perhaps because it -# expects an apk, not a library. - -include $(BUILD_PACKAGE) |