Only set nterp entrypoint after a class is verified.
If a method needs lock counting, we need to use the switch interpreter.
Test: test.py
Test: 825-unbalanced-lock
Change-Id: I50629d20305e01ce2efe75606b00641052378234
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 7fcc8a8..eba25ee 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -3508,15 +3508,10 @@
if (quick_code == nullptr) {
if (method->IsNative()) {
method->SetEntryPointFromQuickCompiledCode(GetQuickGenericJniStub());
- } else if (interpreter::CanRuntimeUseNterp() && CanMethodUseNterp(method)) {
- // The nterp trampoline doesn't do initialization checks, so install the
- // resolution stub if needed.
- if (NeedsClinitCheckBeforeCall(method)) {
- method->SetEntryPointFromQuickCompiledCode(GetQuickResolutionStub());
- } else {
- method->SetEntryPointFromQuickCompiledCode(interpreter::GetNterpEntryPoint());
- }
} else {
+ // Note we cannot use the nterp entrypoint because we do not know if the
+ // method will need the slow interpreter for lock verification. This will
+ // be updated in EnsureSkipAccessChecksMethods.
method->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
}
} else if (enter_interpreter) {
diff --git a/test/825-unbalanced-lock/expected-stderr.txt b/test/825-unbalanced-lock/expected-stderr.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/825-unbalanced-lock/expected-stderr.txt
diff --git a/test/825-unbalanced-lock/expected-stdout.txt b/test/825-unbalanced-lock/expected-stdout.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/825-unbalanced-lock/expected-stdout.txt
diff --git a/test/825-unbalanced-lock/info.txt b/test/825-unbalanced-lock/info.txt
new file mode 100644
index 0000000..3486f73
--- /dev/null
+++ b/test/825-unbalanced-lock/info.txt
@@ -0,0 +1,2 @@
+Regression test for nterp, where we were running a method that needs lock
+counting.
diff --git a/test/825-unbalanced-lock/jasmin/Unbalanced.j b/test/825-unbalanced-lock/jasmin/Unbalanced.j
new file mode 100644
index 0000000..bfa866b
--- /dev/null
+++ b/test/825-unbalanced-lock/jasmin/Unbalanced.j
@@ -0,0 +1,32 @@
+; Copyright (C) 2021 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 Unbalanced
+.super java/lang/Object
+
+.method public <init>()V
+ .limit stack 1
+ .limit locals 1
+ aload_0
+ invokespecial java/lang/Object/<init>()V
+ return
+.end method
+
+.method public unbalanced()V
+ .limit stack 1
+ .limit locals 1
+ aload_0
+ monitorenter
+ return
+.end method
diff --git a/test/825-unbalanced-lock/src/Main.java b/test/825-unbalanced-lock/src/Main.java
new file mode 100644
index 0000000..f25f5ca
--- /dev/null
+++ b/test/825-unbalanced-lock/src/Main.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2021 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;
+import java.lang.reflect.Method;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ Class<?> cls = Class.forName("Unbalanced");
+ Object o = cls.newInstance();
+ try {
+ cls.getMethod("unbalanced").invoke(o);
+ throw new Error("Expected IllegalMonitorStateException");
+ } catch (InvocationTargetException e) {
+ if (!(e.getCause() instanceof IllegalMonitorStateException)) {
+ throw new Error("Expected IllegalMonitorStateException");
+ }
+ }
+ }
+}