OSDN Git Service

ART: Treat throw with non-reference type as hard failure in verifier.
authorPavel Vyssotski <pavel.n.vyssotski@intel.com>
Thu, 11 Feb 2016 14:28:11 +0000 (20:28 +0600)
committerDavid Brazdil <dbrazdil@google.com>
Fri, 12 Feb 2016 15:47:24 +0000 (15:47 +0000)
The code
   const v0, 0xbad
   throw v0
crashes dex2oatd/Quick by DCHECK in art::Mir2Lir::LoadValueDirect.
dex2oat works fine producing VerifyError later in runtime.
Optimizing also pass as it rejects methods with soft failures.

Fix this by rejecting such methods in Verifier.

Bug: 27148248
Change-Id: Ib783f60a210362654d40e84172e7bd579913a4d4
Signed-off-by: Pavel Vyssotski <pavel.n.vyssotski@intel.com>
runtime/verifier/method_verifier.cc
test/800-smali/expected.txt
test/800-smali/smali/b_27148248.smali [new file with mode: 0644]
test/800-smali/src/Main.java

index c7ac172..8d5e6ea 100644 (file)
@@ -2411,6 +2411,8 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) {
       if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(res_type)) {
         if (res_type.IsUninitializedTypes()) {
           Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "thrown exception not initialized";
+        } else if (!res_type.IsReferenceTypes()) {
+          Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "thrown value of non-reference type " << res_type;
         } else {
           Fail(res_type.IsUnresolvedTypes() ? VERIFY_ERROR_NO_CLASS : VERIFY_ERROR_BAD_CLASS_SOFT)
                 << "thrown class " << res_type << " not instanceof Throwable";
index 73ce307..edbb7b5 100644 (file)
@@ -58,4 +58,5 @@ b/26594149 (5)
 b/26594149 (6)
 b/26594149 (7)
 b/26594149 (8)
+b/27148248
 Done!
diff --git a/test/800-smali/smali/b_27148248.smali b/test/800-smali/smali/b_27148248.smali
new file mode 100644 (file)
index 0000000..4601cc6
--- /dev/null
@@ -0,0 +1,27 @@
+# Copyright (C) 2016 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.
+
+.class public LB27148248;
+
+# Regression for dex2oatd crash during compilation of method which
+# used to throw with argument of non-reference type.
+
+.super Ljava/lang/Object;
+
+.method public static run()V
+   .registers 1
+   const v0, 0xbad
+   throw v0
+.end method
+
index b0eff5d..2ea3367 100644 (file)
@@ -160,6 +160,8 @@ public class Main {
                 null));
         testCases.add(new TestCase("b/26594149 (8)", "B26594149_8", "run", null, new VerifyError(),
                 null));
+        testCases.add(new TestCase("b/27148248", "B27148248", "run", null, new VerifyError(),
+                null));
     }
 
     public void runTests() {