Skip to content

Commit 830f291

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm] Use a wrapper for bootstrap natives too.
-80k (-0.33%) out/ProductX64/exe.stripped/dart -76k (-1.59%) out/ProductX64/exe.stripped/dart_precompiled_runtime Change-Id: Ib19aea40aa7a556ae90852ac30c8c08ce0a8b677 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125306 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 29ff784 commit 830f291

15 files changed

Lines changed: 158 additions & 452 deletions

runtime/vm/bootstrap_natives.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace dart {
2323
// point.
2424
static struct NativeEntries {
2525
const char* name_;
26-
Dart_NativeFunction function_;
26+
BootstrapNativeFunction function_;
2727
int argument_count_;
2828
} BootStrapEntries[] = {BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY)
2929
#if !defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/bootstrap_natives.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ class BootstrapNatives : public AllStatic {
485485
static const uint8_t* Symbol(Dart_NativeFunction* nf);
486486

487487
#define DECLARE_BOOTSTRAP_NATIVE(name, ignored) \
488-
static void DN_##name(Dart_NativeArguments args);
488+
static RawObject* DN_##name(Thread* thread, Zone* zone, \
489+
NativeArguments* arguments);
489490

490491
BOOTSTRAP_NATIVE_LIST(DECLARE_BOOTSTRAP_NATIVE)
491492
#if !defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/compiler/backend/il_arm.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,19 +966,9 @@ void NativeCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
966966
entry = reinterpret_cast<uword>(native_c_function());
967967
if (is_bootstrap_native()) {
968968
stub = &StubCode::CallBootstrapNative();
969-
#if defined(USING_SIMULATOR)
970-
entry = Simulator::RedirectExternalReference(
971-
entry, Simulator::kBootstrapNativeCall, NativeEntry::kNumArguments);
972-
#endif
973969
} else if (is_auto_scope()) {
974-
// In the case of non bootstrap native methods the CallNativeCFunction
975-
// stub generates the redirection address when running under the simulator
976-
// and hence we do not change 'entry' here.
977970
stub = &StubCode::CallAutoScopeNative();
978971
} else {
979-
// In the case of non bootstrap native methods the CallNativeCFunction
980-
// stub generates the redirection address when running under the simulator
981-
// and hence we do not change 'entry' here.
982972
stub = &StubCode::CallNoScopeNative();
983973
}
984974
}

runtime/vm/compiler/backend/il_arm64.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -845,19 +845,9 @@ void NativeCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
845845
entry = reinterpret_cast<uword>(native_c_function());
846846
if (is_bootstrap_native()) {
847847
stub = &StubCode::CallBootstrapNative();
848-
#if defined(USING_SIMULATOR)
849-
entry = Simulator::RedirectExternalReference(
850-
entry, Simulator::kBootstrapNativeCall, NativeEntry::kNumArguments);
851-
#endif
852848
} else if (is_auto_scope()) {
853-
// In the case of non bootstrap native methods the CallNativeCFunction
854-
// stub generates the redirection address when running under the simulator
855-
// and hence we do not change 'entry' here.
856849
stub = &StubCode::CallAutoScopeNative();
857850
} else {
858-
// In the case of non bootstrap native methods the CallNativeCFunction
859-
// stub generates the redirection address when running under the simulator
860-
// and hence we do not change 'entry' here.
861851
stub = &StubCode::CallNoScopeNative();
862852
}
863853
}

runtime/vm/compiler/runtime_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ class Thread : public AllStatic {
699699
static word call_native_through_safepoint_stub_offset();
700700
static word call_native_through_safepoint_entry_point_offset();
701701

702+
static word bootstrap_native_wrapper_entry_point_offset();
702703
static word no_scope_native_wrapper_entry_point_offset();
703704
static word auto_scope_native_wrapper_entry_point_offset();
704705

runtime/vm/compiler/runtime_offsets_extracted.h

Lines changed: 95 additions & 87 deletions
Large diffs are not rendered by default.

runtime/vm/compiler/runtime_offsets_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
FIELD(Thread, auto_scope_native_wrapper_entry_point_offset) \
151151
FIELD(Thread, bool_false_offset) \
152152
FIELD(Thread, bool_true_offset) \
153+
FIELD(Thread, bootstrap_native_wrapper_entry_point_offset) \
153154
FIELD(Thread, call_to_runtime_entry_point_offset) \
154155
FIELD(Thread, call_to_runtime_stub_offset) \
155156
FIELD(Thread, dart_stream_offset) \

runtime/vm/compiler/stub_code_compiler_arm.cc

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -602,83 +602,10 @@ void StubCodeCompiler::GenerateCallAutoScopeNativeStub(Assembler* assembler) {
602602
// R2 : address of first argument in argument array.
603603
// R1 : argc_tag including number of arguments and function kind.
604604
void StubCodeCompiler::GenerateCallBootstrapNativeStub(Assembler* assembler) {
605-
const intptr_t thread_offset = target::NativeArguments::thread_offset();
606-
const intptr_t argc_tag_offset = target::NativeArguments::argc_tag_offset();
607-
const intptr_t argv_offset = target::NativeArguments::argv_offset();
608-
const intptr_t retval_offset = target::NativeArguments::retval_offset();
609-
610-
__ EnterStubFrame();
611-
612-
// Save exit frame information to enable stack walking as we are about
613-
// to transition to native code.
614-
__ StoreToOffset(kWord, FP, THR,
615-
target::Thread::top_exit_frame_info_offset());
616-
617-
#if defined(DEBUG)
618-
{
619-
Label ok;
620-
// Check that we are always entering from Dart code.
621-
__ LoadFromOffset(kWord, R8, THR, target::Thread::vm_tag_offset());
622-
__ CompareImmediate(R8, VMTag::kDartCompiledTagId);
623-
__ b(&ok, EQ);
624-
__ Stop("Not coming from Dart code.");
625-
__ Bind(&ok);
626-
}
627-
#endif
628-
629-
// Mark that the thread is executing native code.
630-
__ StoreToOffset(kWord, R9, THR, target::Thread::vm_tag_offset());
631-
632-
// Reserve space for the native arguments structure passed on the stack (the
633-
// outgoing pointer parameter to the native arguments structure is passed in
634-
// R0) and align frame before entering the C++ world.
635-
__ ReserveAlignedFrameSpace(target::NativeArguments::StructSize());
636-
637-
// Initialize target::NativeArguments structure and call native function.
638-
// Registers R0, R1, R2, and R3 are used.
639-
640-
ASSERT(thread_offset == 0 * target::kWordSize);
641-
// Set thread in NativeArgs.
642-
__ mov(R0, Operand(THR));
643-
644-
// There are no native calls to closures, so we do not need to set the tag
645-
// bits kClosureFunctionBit and kInstanceFunctionBit in argc_tag_.
646-
ASSERT(argc_tag_offset == 1 * target::kWordSize);
647-
// Set argc in target::NativeArguments: R1 already contains argc.
648-
649-
ASSERT(argv_offset == 2 * target::kWordSize);
650-
// Set argv in target::NativeArguments: R2 already contains argv.
651-
652-
// Set retval in NativeArgs.
653-
ASSERT(retval_offset == 3 * target::kWordSize);
654-
__ add(R3, FP, Operand(2 * target::kWordSize));
655-
656-
// Passing the structure by value as in runtime calls would require changing
657-
// Dart API for native functions.
658-
// For now, space is reserved on the stack and we pass a pointer to it.
659-
__ stm(IA, SP, (1 << R0) | (1 << R1) | (1 << R2) | (1 << R3));
660-
__ mov(R0, Operand(SP)); // Pass the pointer to the target::NativeArguments.
661-
662-
// Call native function or redirection via simulator.
663-
__ blx(R9);
664-
665-
// Mark that the thread is executing Dart code.
666-
__ LoadImmediate(R2, VMTag::kDartCompiledTagId);
667-
__ StoreToOffset(kWord, R2, THR, target::Thread::vm_tag_offset());
668-
669-
// Reset exit frame information in Isolate structure.
670-
__ LoadImmediate(R2, 0);
671-
__ StoreToOffset(kWord, R2, THR,
672-
target::Thread::top_exit_frame_info_offset());
673-
674-
// Restore the global object pool after returning from runtime (old space is
675-
// moving, so the GOP could have been relocated).
676-
if (FLAG_precompiled_mode && FLAG_use_bare_instructions) {
677-
__ ldr(PP, Address(THR, target::Thread::global_object_pool_offset()));
678-
}
679-
680-
__ LeaveStubFrame();
681-
__ Ret();
605+
GenerateCallNativeWithWrapperStub(
606+
assembler,
607+
Address(THR,
608+
target::Thread::bootstrap_native_wrapper_entry_point_offset()));
682609
}
683610

684611
// Input parameters:

runtime/vm/compiler/stub_code_compiler_arm64.cc

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -667,98 +667,10 @@ void StubCodeCompiler::GenerateCallAutoScopeNativeStub(Assembler* assembler) {
667667
// R2 : address of first argument in argument array.
668668
// R1 : argc_tag including number of arguments and function kind.
669669
void StubCodeCompiler::GenerateCallBootstrapNativeStub(Assembler* assembler) {
670-
const intptr_t thread_offset = target::NativeArguments::thread_offset();
671-
const intptr_t argc_tag_offset = target::NativeArguments::argc_tag_offset();
672-
const intptr_t argv_offset = target::NativeArguments::argv_offset();
673-
const intptr_t retval_offset = target::NativeArguments::retval_offset();
674-
675-
__ EnterStubFrame();
676-
677-
// Save exit frame information to enable stack walking as we are about
678-
// to transition to native code.
679-
__ StoreToOffset(FP, THR, target::Thread::top_exit_frame_info_offset());
680-
681-
#if defined(DEBUG)
682-
{
683-
Label ok;
684-
// Check that we are always entering from Dart code.
685-
__ LoadFromOffset(R6, THR, target::Thread::vm_tag_offset());
686-
__ CompareImmediate(R6, VMTag::kDartCompiledTagId);
687-
__ b(&ok, EQ);
688-
__ Stop("Not coming from Dart code.");
689-
__ Bind(&ok);
690-
}
691-
#endif
692-
693-
// Mark that the thread is executing native code.
694-
__ StoreToOffset(R5, THR, target::Thread::vm_tag_offset());
695-
696-
// Reserve space for the native arguments structure passed on the stack (the
697-
// outgoing pointer parameter to the native arguments structure is passed in
698-
// R0) and align frame before entering the C++ world.
699-
__ ReserveAlignedFrameSpace(target::NativeArguments::StructSize());
700-
701-
// Initialize target::NativeArguments structure and call native function.
702-
// Registers R0, R1, R2, and R3 are used.
703-
704-
ASSERT(thread_offset == 0 * target::kWordSize);
705-
// Set thread in NativeArgs.
706-
__ mov(R0, THR);
707-
708-
// There are no native calls to closures, so we do not need to set the tag
709-
// bits kClosureFunctionBit and kInstanceFunctionBit in argc_tag_.
710-
ASSERT(argc_tag_offset == 1 * target::kWordSize);
711-
// Set argc in target::NativeArguments: R1 already contains argc.
712-
713-
ASSERT(argv_offset == 2 * target::kWordSize);
714-
// Set argv in target::NativeArguments: R2 already contains argv.
715-
716-
// Set retval in NativeArgs.
717-
ASSERT(retval_offset == 3 * target::kWordSize);
718-
__ AddImmediate(R3, FP, 2 * target::kWordSize);
719-
720-
// Passing the structure by value as in runtime calls would require changing
721-
// Dart API for native functions.
722-
// For now, space is reserved on the stack and we pass a pointer to it.
723-
__ StoreToOffset(R0, SP, thread_offset);
724-
__ StoreToOffset(R1, SP, argc_tag_offset);
725-
__ StoreToOffset(R2, SP, argv_offset);
726-
__ StoreToOffset(R3, SP, retval_offset);
727-
__ mov(R0, SP); // Pass the pointer to the target::NativeArguments.
728-
729-
// We are entering runtime code, so the C stack pointer must be restored from
730-
// the stack limit to the top of the stack. We cache the stack limit address
731-
// in the Dart SP register, which is callee-saved in the C ABI.
732-
__ mov(R25, CSP);
733-
__ mov(CSP, SP);
734-
735-
// Call native function or redirection via simulator.
736-
__ blr(R5);
737-
738-
// Restore SP and CSP.
739-
__ mov(SP, CSP);
740-
__ mov(CSP, R25);
741-
742-
// Refresh write barrier mask.
743-
__ ldr(BARRIER_MASK,
744-
Address(THR, target::Thread::write_barrier_mask_offset()));
745-
746-
// Mark that the thread is executing Dart code.
747-
__ LoadImmediate(R2, VMTag::kDartCompiledTagId);
748-
__ StoreToOffset(R2, THR, target::Thread::vm_tag_offset());
749-
750-
// Reset exit frame information in Isolate structure.
751-
__ StoreToOffset(ZR, THR, target::Thread::top_exit_frame_info_offset());
752-
753-
// Restore the global object pool after returning from runtime (old space is
754-
// moving, so the GOP could have been relocated).
755-
if (FLAG_precompiled_mode && FLAG_use_bare_instructions) {
756-
__ ldr(PP, Address(THR, target::Thread::global_object_pool_offset()));
757-
__ sub(PP, PP, Operand(kHeapObjectTag)); // Pool in PP is untagged!
758-
}
759-
760-
__ LeaveStubFrame();
761-
__ ret();
670+
GenerateCallNativeWithWrapperStub(
671+
assembler,
672+
Address(THR,
673+
target::Thread::bootstrap_native_wrapper_entry_point_offset()));
762674
}
763675

764676
// Input parameters:

runtime/vm/compiler/stub_code_compiler_ia32.cc

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -417,67 +417,10 @@ void StubCodeCompiler::GenerateCallAutoScopeNativeStub(Assembler* assembler) {
417417
// ECX : address of the native function to call.
418418
// EDX : argc_tag including number of arguments and function kind.
419419
void StubCodeCompiler::GenerateCallBootstrapNativeStub(Assembler* assembler) {
420-
const intptr_t native_args_struct_offset = target::kWordSize;
421-
const intptr_t thread_offset =
422-
target::NativeArguments::thread_offset() + native_args_struct_offset;
423-
const intptr_t argc_tag_offset =
424-
target::NativeArguments::argc_tag_offset() + native_args_struct_offset;
425-
const intptr_t argv_offset =
426-
target::NativeArguments::argv_offset() + native_args_struct_offset;
427-
const intptr_t retval_offset =
428-
target::NativeArguments::retval_offset() + native_args_struct_offset;
429-
430-
__ EnterStubFrame();
431-
432-
// Save exit frame information to enable stack walking as we are about
433-
// to transition to dart VM code.
434-
__ movl(Address(THR, target::Thread::top_exit_frame_info_offset()), EBP);
435-
436-
#if defined(DEBUG)
437-
{
438-
Label ok;
439-
// Check that we are always entering from Dart code.
440-
__ cmpl(Assembler::VMTagAddress(), Immediate(VMTag::kDartCompiledTagId));
441-
__ j(EQUAL, &ok, Assembler::kNearJump);
442-
__ Stop("Not coming from Dart code.");
443-
__ Bind(&ok);
444-
}
445-
#endif
446-
447-
// Mark that the thread is executing native code.
448-
__ movl(Assembler::VMTagAddress(), ECX);
449-
450-
// Reserve space for the native arguments structure, the outgoing parameter
451-
// (pointer to the native arguments structure) and align frame before
452-
// entering the C++ world.
453-
__ AddImmediate(
454-
ESP,
455-
Immediate(-static_cast<int32_t>(target::NativeArguments::StructSize()) -
456-
target::kWordSize));
457-
if (OS::ActivationFrameAlignment() > 1) {
458-
__ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1)));
459-
}
460-
461-
// Pass NativeArguments structure by value and call native function.
462-
__ movl(Address(ESP, thread_offset), THR); // Set thread in NativeArgs.
463-
__ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments.
464-
__ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments.
465-
__ leal(EAX,
466-
Address(EBP, 2 * target::kWordSize)); // Compute return value addr.
467-
__ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments.
468-
__ leal(EAX,
469-
Address(ESP, target::kWordSize)); // Pointer to the NativeArguments.
470-
__ movl(Address(ESP, 0), EAX); // Pass the pointer to the NativeArguments.
471-
__ call(ECX);
472-
473-
__ movl(Assembler::VMTagAddress(), Immediate(VMTag::kDartCompiledTagId));
474-
475-
// Reset exit frame information in Isolate structure.
476-
__ movl(Address(THR, target::Thread::top_exit_frame_info_offset()),
477-
Immediate(0));
478-
479-
__ LeaveFrame();
480-
__ ret();
420+
GenerateCallNativeWithWrapperStub(
421+
assembler,
422+
Address(THR,
423+
target::Thread::bootstrap_native_wrapper_entry_point_offset()));
481424
}
482425

483426
// Input parameters:

0 commit comments

Comments
 (0)