diff options
-rw-r--r-- | compiler/optimizing/inliner.cc | 4 | ||||
-rw-r--r-- | test/587-inline-class-error/expected.txt | 0 | ||||
-rw-r--r-- | test/587-inline-class-error/info.txt | 2 | ||||
-rw-r--r-- | test/587-inline-class-error/smali/SuperVerifyError.smali | 27 | ||||
-rw-r--r-- | test/587-inline-class-error/smali/TestCase.smali | 33 | ||||
-rw-r--r-- | test/587-inline-class-error/smali/VerifyError.smali | 28 | ||||
-rw-r--r-- | test/587-inline-class-error/src/Main.java | 37 |
7 files changed, 131 insertions, 0 deletions
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 573b58340c..440a2821c1 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -144,6 +144,10 @@ static ArtMethod* FindVirtualOrInterfaceTarget(HInvoke* invoke, ArtMethod* resol } else if (!resolved_method->GetDeclaringClass()->IsAssignableFrom(info.GetTypeHandle().Get())) { // The method that we're trying to call is not in the receiver's class or super classes. return nullptr; + } else if (info.GetTypeHandle()->IsErroneous()) { + // If the type is erroneous, do not go further, as we are going to query the vtable or + // imt table, that we can only safely do on non-erroneous classes. + return nullptr; } ClassLinker* cl = Runtime::Current()->GetClassLinker(); diff --git a/test/587-inline-class-error/expected.txt b/test/587-inline-class-error/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/587-inline-class-error/expected.txt diff --git a/test/587-inline-class-error/info.txt b/test/587-inline-class-error/info.txt new file mode 100644 index 0000000000..7f244f673c --- /dev/null +++ b/test/587-inline-class-error/info.txt @@ -0,0 +1,2 @@ +Regression test for the inliner that used to crash while +trying to find a method for an erroneous class. diff --git a/test/587-inline-class-error/smali/SuperVerifyError.smali b/test/587-inline-class-error/smali/SuperVerifyError.smali new file mode 100644 index 0000000000..b63cba0a3b --- /dev/null +++ b/test/587-inline-class-error/smali/SuperVerifyError.smali @@ -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 LSuperVerifyError; + +.super Ljava/lang/Object; + +.method public final foo()V + .registers 1 + return-void +.end method + +.method public bar()V + .registers 1 + return-void +.end method diff --git a/test/587-inline-class-error/smali/TestCase.smali b/test/587-inline-class-error/smali/TestCase.smali new file mode 100644 index 0000000000..7c991ed003 --- /dev/null +++ b/test/587-inline-class-error/smali/TestCase.smali @@ -0,0 +1,33 @@ +# 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 LTestCase; + +.super Ljava/lang/Object; + +.method public static topLevel()V + .registers 2 + const v0, 0x1 + new-array v0, v0, [LVerifyError; + invoke-static {v0}, LTestCase;->test([LVerifyError;)V + return-void +.end method + +.method public static test([LVerifyError;)V + .registers 2 + const v0, 0x0 + aget-object v1, v1, v0 + invoke-virtual {v1}, LSuperVerifyError;->bar()V + return-void +.end method diff --git a/test/587-inline-class-error/smali/VerifyError.smali b/test/587-inline-class-error/smali/VerifyError.smali new file mode 100644 index 0000000000..b821b7132e --- /dev/null +++ b/test/587-inline-class-error/smali/VerifyError.smali @@ -0,0 +1,28 @@ +# 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 final LVerifyError; + +.super LSuperVerifyError; + +# Override a final method to put this class in the error state. +.method public foo()V + .registers 1 + return-void +.end method + +# Having a static field in the class is needed to get the +# right initialization for the embedded vtable length of a +# class. +.field public static i:I diff --git a/test/587-inline-class-error/src/Main.java b/test/587-inline-class-error/src/Main.java new file mode 100644 index 0000000000..3402fabb2c --- /dev/null +++ b/test/587-inline-class-error/src/Main.java @@ -0,0 +1,37 @@ +/* + * 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. + */ + +import java.lang.reflect.InvocationTargetException; + +public class Main { + public static void main(String[] args) throws Exception { + try { + Class<?> v = Class.forName("VerifyError"); + throw new Error("Expected LinkageError"); + } catch (LinkageError e) { + // expected + } + + try { + Class.forName("TestCase").getMethod("topLevel").invoke(null); + throw new Error("Expected InvocationTargetException"); + } catch (InvocationTargetException e) { + if (!(e.getCause() instanceof NullPointerException)) { + throw new Error("Expected NullPointerException, got " + e.getCause()); + } + } + } +} |