Skip to content

Commit

Permalink
Fix missing suspend check in nterp for goto32 +0
Browse files Browse the repository at this point in the history
Test: 830-goto-zero
Bug: 200660605
Change-Id: I2267fa3d2842cc84e2e5b3ee8cf04989cd423a50
  • Loading branch information
Nicolas Geoffray committed Sep 22, 2021
1 parent 145f969 commit d726cb1
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 8 deletions.
5 changes: 3 additions & 2 deletions runtime/interpreter/mterp/arm64ng/main.S
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ END \name
.endm

.macro BRANCH
// Update method counter and do a suspend check if the branch is negative.
tbnz wINST, #31, 2f
// Update method counter and do a suspend check if the branch is negative or zero.
cmp wINST, #0
b.le 2f
1:
add xPC, xPC, wINST, sxtw #1 // update xPC
FETCH wINST, 0 // load wINST
Expand Down
4 changes: 2 additions & 2 deletions runtime/interpreter/mterp/armng/main.S
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ END \name
.endm

.macro BRANCH
// Update method counter and do a suspend check if the branch is negative.
// Update method counter and do a suspend check if the branch is negative or zero.
cmp rINST, #0
blt 2f
ble 2f
1:
add r2, rINST, rINST // r2<- byte offset
FETCH_ADVANCE_INST_RB r2 // update xPC, load rINST
Expand Down
4 changes: 2 additions & 2 deletions runtime/interpreter/mterp/x86_64ng/main.S
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ END_FUNCTION \name


.macro BRANCH
// Update method counter and do a suspend check if the branch is negative.
// Update method counter and do a suspend check if the branch is negative or zero.
testq rINSTq, rINSTq
js 3f
jle 3f
2:
leaq (rPC, rINSTq, 2), rPC
FETCH_INST
Expand Down
4 changes: 2 additions & 2 deletions runtime/interpreter/mterp/x86ng/main.S
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ END_FUNCTION \name


.macro BRANCH
// Update method counter and do a suspend check if the branch is negative.
// Update method counter and do a suspend check if the branch is negative or zero.
testl rINST, rINST
js 3f
jle 3f
2:
leal (rPC, rINST, 2), rPC
FETCH_INST
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/830-goto-zero/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Regression test for missing suspend checks in nterp when branching to zero.
29 changes: 29 additions & 0 deletions test/830-goto-zero/smali/SmaliClass.smali
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 LSmaliClass;
.super Ljava/lang/Object;

.method public constructor <init>()V
.registers 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method

.method public static gotoZero()V
.registers 0
:Linfinite_loop
goto/32 :Linfinite_loop
return-void
.end method
43 changes: 43 additions & 0 deletions test/830-goto-zero/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.Method;

public class Main {

public static void main(String args[]) throws Exception {
b2302318Test();
}

static void b2302318Test() {
SpinThread st = new SpinThread();
st.setDaemon(true);
st.start();
Thread.yield();
Runtime.getRuntime().gc();
}

}
class SpinThread extends Thread {
public void run() {
try {
Class<?> cls = Class.forName("SmaliClass");
cls.getDeclaredMethod("gotoZero").invoke(null);
} catch (Exception e) {
throw new Error(e);
}
}
}
1 change: 1 addition & 0 deletions test/knownfailures.json
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@
"821-many-args",
"822-hiddenapi-future",
"827-resolve-method",
"830-goto-zero",
"999-redefine-hiddenapi",
"1000-non-moving-space-stress",
"1001-app-image-regions",
Expand Down

0 comments on commit d726cb1

Please sign in to comment.