Use implicit suspend check in JIT.
Also generalize how implicit checks get passed to the JIT.
Test: test.py
Bug: 38383823
Change-Id: Ia1c252375dbafea682d4564bfb788fa131b8d902
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index 44a4283..7002636 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -68,6 +68,10 @@
compiler_options_->SetDebuggable(runtime->IsJavaDebuggable());
}
+ compiler_options_->implicit_null_checks_ = runtime->GetImplicitNullChecks();
+ compiler_options_->implicit_so_checks_ = runtime->GetImplicitStackOverflowChecks();
+ compiler_options_->implicit_suspend_checks_ = runtime->GetImplicitSuspendChecks();
+
const InstructionSet instruction_set = compiler_options_->GetInstructionSet();
if (kRuntimeISA == InstructionSet::kArm) {
DCHECK_EQ(instruction_set, InstructionSet::kThumb2);
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 1f5c58c..853ded0 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -786,11 +786,10 @@
create_and_throw();
CHECK(self->IsExceptionPending());
- bool explicit_overflow_check = Runtime::Current()->ExplicitStackOverflowChecks();
self->ResetDefaultStackEnd(); // Return to default stack size.
// And restore protection if implicit checks are on.
- if (!explicit_overflow_check) {
+ if (Runtime::Current()->GetImplicitStackOverflowChecks()) {
self->ProtectStack();
}
}
diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc
index 0cce09e..4339120 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -343,7 +343,7 @@
JValue* result,
bool stay_in_interpreter) {
DCHECK_EQ(self, Thread::Current());
- bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
+ bool implicit_check = Runtime::Current()->GetImplicitStackOverflowChecks();
if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
ThrowStackOverflowError(self);
return;
@@ -569,7 +569,7 @@
JValue EnterInterpreterFromEntryPoint(Thread* self, const CodeItemDataAccessor& accessor,
ShadowFrame* shadow_frame) {
DCHECK_EQ(self, Thread::Current());
- bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
+ bool implicit_check = Runtime::Current()->GetImplicitStackOverflowChecks();
if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
ThrowStackOverflowError(self);
return JValue();
@@ -586,7 +586,7 @@
const CodeItemDataAccessor& accessor,
ShadowFrame* shadow_frame,
JValue* result) {
- bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
+ bool implicit_check = Runtime::Current()->GetImplicitStackOverflowChecks();
if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
ThrowStackOverflowError(self);
return;
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 937a3b0..cafe747 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -58,7 +58,7 @@
bool CheckStackOverflow(Thread* self, size_t frame_size)
REQUIRES_SHARED(Locks::mutator_lock_) {
- bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
+ bool implicit_check = Runtime::Current()->GetImplicitStackOverflowChecks();
uint8_t* stack_end = self->GetStackEndForInterpreter(implicit_check);
if (UNLIKELY(__builtin_frame_address(0) < stack_end + frame_size)) {
ThrowStackOverflowError(self);
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 0c99cf9..9f835bb 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -631,8 +631,16 @@
void AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* arg_vector) const;
- bool ExplicitStackOverflowChecks() const {
- return !implicit_so_checks_;
+ bool GetImplicitStackOverflowChecks() const {
+ return implicit_so_checks_;
+ }
+
+ bool GetImplicitSuspendChecks() const {
+ return implicit_suspend_checks_;
+ }
+
+ bool GetImplicitNullChecks() const {
+ return implicit_null_checks_;
}
void DisableVerifier();
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 73f2a00..4b5ec18 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -707,16 +707,16 @@
stack_size = PTHREAD_STACK_MIN;
}
- if (Runtime::Current()->ExplicitStackOverflowChecks()) {
- // It's likely that callers are trying to ensure they have at least a certain amount of
- // stack space, so we should add our reserved space on top of what they requested, rather
- // than implicitly take it away from them.
- stack_size += GetStackOverflowReservedBytes(kRuntimeISA);
- } else {
+ if (Runtime::Current()->GetImplicitStackOverflowChecks()) {
// If we are going to use implicit stack checks, allocate space for the protected
// region at the bottom of the stack.
stack_size += Thread::kStackOverflowImplicitCheckSize +
GetStackOverflowReservedBytes(kRuntimeISA);
+ } else {
+ // It's likely that callers are trying to ensure they have at least a certain amount of
+ // stack space, so we should add our reserved space on top of what they requested, rather
+ // than implicitly take it away from them.
+ stack_size += GetStackOverflowReservedBytes(kRuntimeISA);
}
// Some systems require the stack size to be a multiple of the system page size, so round up.
@@ -1328,7 +1328,8 @@
// Set stack_end_ to the bottom of the stack saving space of stack overflows
Runtime* runtime = Runtime::Current();
- bool implicit_stack_check = !runtime->ExplicitStackOverflowChecks() && !runtime->IsAotCompiler();
+ bool implicit_stack_check =
+ runtime->GetImplicitStackOverflowChecks() && !runtime->IsAotCompiler();
ResetDefaultStackEnd();
@@ -4327,7 +4328,7 @@
tlsPtr_.stack_end = tlsPtr_.stack_begin;
// Remove the stack overflow protection if is it set up.
- bool implicit_stack_check = !Runtime::Current()->ExplicitStackOverflowChecks();
+ bool implicit_stack_check = Runtime::Current()->GetImplicitStackOverflowChecks();
if (implicit_stack_check) {
if (!UnprotectStack()) {
LOG(ERROR) << "Unable to remove stack protection for stack overflow";