@@ -3201,16 +3201,33 @@ pub fn gen_entry_point(iseq: IseqPtr, ec: EcPtr, jit_exception: bool) -> Option<
32013201 let cb = CodegenGlobals :: get_inline_cb ( ) ;
32023202 let ocb = CodegenGlobals :: get_outlined_cb ( ) ;
32033203
3204+ let code_ptr = gen_entry_point_body ( blockid, stack_size, ec, jit_exception, cb, ocb) ;
3205+
3206+ cb. mark_all_executable ( ) ;
3207+ ocb. unwrap ( ) . mark_all_executable ( ) ;
3208+
3209+ code_ptr
3210+ }
3211+
3212+ fn gen_entry_point_body ( blockid : BlockId , stack_size : u8 , ec : EcPtr , jit_exception : bool , cb : & mut CodeBlock , ocb : & mut OutlinedCb ) -> Option < * const u8 > {
32043213 // Write the interpreter entry prologue. Might be NULL when out of memory.
3205- let code_ptr = gen_entry_prologue ( cb, ocb, iseq , insn_idx , jit_exception) ;
3214+ let ( code_ptr, reg_mapping ) = gen_entry_prologue ( cb, ocb, blockid , stack_size , jit_exception) ? ;
32063215
3207- // Try to generate code for the entry block
3216+ // Find or compile a block version
32083217 let mut ctx = Context :: default ( ) ;
32093218 ctx. stack_size = stack_size;
3210- let block = gen_block_series ( blockid, & ctx, ec, cb, ocb) ;
3211-
3212- cb. mark_all_executable ( ) ;
3213- ocb. unwrap ( ) . mark_all_executable ( ) ;
3219+ ctx. reg_mapping = reg_mapping;
3220+ let block = match find_block_version ( blockid, & ctx) {
3221+ // If an existing block is found, generate a jump to the block.
3222+ Some ( blockref) => {
3223+ let mut asm = Assembler :: new_without_iseq ( ) ;
3224+ asm. jmp ( unsafe { blockref. as_ref ( ) } . start_addr . into ( ) ) ;
3225+ asm. compile ( cb, Some ( ocb) ) ?;
3226+ Some ( blockref)
3227+ }
3228+ // If this block hasn't yet been compiled, generate blocks after the entry guard.
3229+ None => gen_block_series ( blockid, & ctx, ec, cb, ocb) ,
3230+ } ;
32143231
32153232 match block {
32163233 // Compilation failed
@@ -3235,7 +3252,7 @@ pub fn gen_entry_point(iseq: IseqPtr, ec: EcPtr, jit_exception: bool) -> Option<
32353252 incr_counter ! ( compiled_iseq_entry) ;
32363253
32373254 // Compilation successful and block not empty
3238- code_ptr . map ( |ptr| ptr . raw_ptr ( cb) )
3255+ Some ( code_ptr . raw_ptr ( cb) )
32393256}
32403257
32413258// Change the entry's jump target from an entry stub to a next entry
@@ -3310,20 +3327,22 @@ fn entry_stub_hit_body(
33103327 let cfp = unsafe { get_ec_cfp ( ec) } ;
33113328 let iseq = unsafe { get_cfp_iseq ( cfp) } ;
33123329 let insn_idx = iseq_pc_to_insn_idx ( iseq, unsafe { get_cfp_pc ( cfp) } ) ?;
3330+ let blockid = BlockId { iseq, idx : insn_idx } ;
33133331 let stack_size: u8 = unsafe {
33143332 u8:: try_from ( get_cfp_sp ( cfp) . offset_from ( get_cfp_bp ( cfp) ) ) . ok ( ) ?
33153333 } ;
33163334
33173335 // Compile a new entry guard as a next entry
33183336 let next_entry = cb. get_write_ptr ( ) ;
3319- let mut asm = Assembler :: new_without_iseq ( ) ;
3320- let pending_entry = gen_entry_chain_guard ( & mut asm, ocb, iseq, insn_idx) ?;
3337+ let mut asm = Assembler :: new ( unsafe { get_iseq_body_local_table_size ( iseq) } ) ;
3338+ let pending_entry = gen_entry_chain_guard ( & mut asm, ocb, blockid) ?;
3339+ let reg_mapping = gen_entry_reg_mapping ( & mut asm, blockid, stack_size) ;
33213340 asm. compile ( cb, Some ( ocb) ) ?;
33223341
33233342 // Find or compile a block version
3324- let blockid = BlockId { iseq, idx : insn_idx } ;
33253343 let mut ctx = Context :: default ( ) ;
33263344 ctx. stack_size = stack_size;
3345+ ctx. reg_mapping = reg_mapping;
33273346 let blockref = match find_block_version ( blockid, & ctx) {
33283347 // If an existing block is found, generate a jump to the block.
33293348 Some ( blockref) => {
@@ -3347,8 +3366,8 @@ fn entry_stub_hit_body(
33473366 get_or_create_iseq_payload ( iseq) . entries . push ( pending_entry. into_entry ( ) ) ;
33483367 }
33493368
3350- // Let the stub jump to the block
3351- blockref . map ( |block| unsafe { block . as_ref ( ) } . start_addr . raw_ptr ( cb) )
3369+ // Let the stub jump to the entry to load entry registers
3370+ Some ( next_entry . raw_ptr ( cb) )
33523371}
33533372
33543373/// Generate a stub that calls entry_stub_hit
0 commit comments