void ArtInterpreterToCompiledCodeBridge(Thread* self,
ArtMethod* caller,
- const DexFile::CodeItem* code_item,
ShadowFrame* shadow_frame,
+ uint16_t arg_offset,
JValue* result);
} // namespace interpreter
interpreter::ArtInterpreterToInterpreterBridge(self, code_item, callee_frame, result);
} else {
interpreter::ArtInterpreterToCompiledCodeBridge(
- self, caller_method, code_item, callee_frame, result);
+ self, caller_method, callee_frame, first_dest_reg, result);
}
} else {
interpreter::UnstartedRuntime::Invoke(self, code_item, callee_frame, result, first_dest_reg);
// Pop the shadow frame before calling into compiled code.
self->PopShadowFrame();
- ArtInterpreterToCompiledCodeBridge(self, nullptr, code_item, &shadow_frame, &result);
+ // Calculate the offset of the first input reg. The input registers are in the high regs.
+ // If there is no code item, all the registers are inputs.
+ uint16_t arg_offset = (code_item == nullptr)
+ ? 0
+ : code_item->registers_size_ - code_item->ins_size_;
+ ArtInterpreterToCompiledCodeBridge(self, nullptr, &shadow_frame, arg_offset, &result);
// Push the shadow frame back as the caller will expect it.
self->PushShadowFrame(&shadow_frame);
void ArtInterpreterToCompiledCodeBridge(Thread* self,
ArtMethod* caller,
- const DexFile::CodeItem* code_item,
ShadowFrame* shadow_frame,
+ uint16_t arg_offset,
JValue* result)
REQUIRES_SHARED(Locks::mutator_lock_) {
ArtMethod* method = shadow_frame->GetMethod();
self->PushShadowFrame(shadow_frame);
StackHandleScope<1> hs(self);
Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
- if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
- true))) {
+ if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
+ self, h_class, true, true))) {
self->PopShadowFrame();
DCHECK(self->IsExceptionPending());
return;
}
self->PopShadowFrame();
CHECK(h_class->IsInitializing());
- // Reload from shadow frame in case the method moved, this is faster than adding a handle.
- method = shadow_frame->GetMethod();
}
}
- uint16_t arg_offset = (code_item == nullptr)
- ? 0
- : code_item->registers_size_ - code_item->ins_size_;
+ // Basic checks for the arg_offset. If there's no code item, the arg_offset must be 0. Otherwise,
+ // check that the arg_offset isn't greater than the number of registers. A stronger check is hard
+ // to do because the method being called may have been replaced if it was a string init method,
+ // and the arguments are handled differently in that case.
+ if (method->GetCodeItem() == nullptr) {
+ DCHECK_EQ(0u, arg_offset);
+ } else {
+ DCHECK_LE(arg_offset, shadow_frame->NumberOfVRegs());
+ }
jit::Jit* jit = Runtime::Current()->GetJit();
if (jit != nullptr && caller != nullptr) {
jit->NotifyInterpreterToCompiledCodeTransition(self, caller);
// Number of registers for the callee's call frame.
uint16_t num_regs;
- if (LIKELY(code_item != nullptr)) {
+ // When transitioning to compiled code, the frame only contains input registers.
+ // We can avoid accessing compiled code items here so they remain untouched during runtime,
+ // saving memory since they never get paged in.
+ bool use_compiler_entrypoint = Runtime::Current()->IsStarted() &&
+ !ClassLinker::ShouldUseInterpreterEntrypoint(
+ called_method, called_method->GetEntryPointFromQuickCompiledCode());
+ if (LIKELY(code_item != nullptr && !use_compiler_entrypoint)) {
num_regs = code_item->registers_size_;
- DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, code_item->ins_size_);
} else {
- DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
+ DCHECK(called_method->IsNative() || called_method->IsProxyMethod() || use_compiler_entrypoint);
num_regs = number_of_inputs;
}
+ // Check that the number of inputs passed in agrees with the code item. If a string initializer
+ // is called, it will have been replaced by an equivalent StringFactory call above, and they
+ // have one fewer input (no this pointer).
+ if (code_item != nullptr) {
+ DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, code_item->ins_size_);
+ }
// Hack for String init:
//