@@ -3201,16 +3201,33 @@ pub fn gen_entry_point(iseq: IseqPtr, ec: EcPtr, jit_exception: bool) -> Option<
3201
3201
let cb = CodegenGlobals :: get_inline_cb ( ) ;
3202
3202
let ocb = CodegenGlobals :: get_outlined_cb ( ) ;
3203
3203
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 > {
3204
3213
// 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) ? ;
3206
3215
3207
- // Try to generate code for the entry block
3216
+ // Find or compile a block version
3208
3217
let mut ctx = Context :: default ( ) ;
3209
3218
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
+ } ;
3214
3231
3215
3232
match block {
3216
3233
// Compilation failed
@@ -3235,7 +3252,7 @@ pub fn gen_entry_point(iseq: IseqPtr, ec: EcPtr, jit_exception: bool) -> Option<
3235
3252
incr_counter ! ( compiled_iseq_entry) ;
3236
3253
3237
3254
// Compilation successful and block not empty
3238
- code_ptr . map ( |ptr| ptr . raw_ptr ( cb) )
3255
+ Some ( code_ptr . raw_ptr ( cb) )
3239
3256
}
3240
3257
3241
3258
// Change the entry's jump target from an entry stub to a next entry
@@ -3310,20 +3327,22 @@ fn entry_stub_hit_body(
3310
3327
let cfp = unsafe { get_ec_cfp ( ec) } ;
3311
3328
let iseq = unsafe { get_cfp_iseq ( cfp) } ;
3312
3329
let insn_idx = iseq_pc_to_insn_idx ( iseq, unsafe { get_cfp_pc ( cfp) } ) ?;
3330
+ let blockid = BlockId { iseq, idx : insn_idx } ;
3313
3331
let stack_size: u8 = unsafe {
3314
3332
u8:: try_from ( get_cfp_sp ( cfp) . offset_from ( get_cfp_bp ( cfp) ) ) . ok ( ) ?
3315
3333
} ;
3316
3334
3317
3335
// Compile a new entry guard as a next entry
3318
3336
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) ;
3321
3340
asm. compile ( cb, Some ( ocb) ) ?;
3322
3341
3323
3342
// Find or compile a block version
3324
- let blockid = BlockId { iseq, idx : insn_idx } ;
3325
3343
let mut ctx = Context :: default ( ) ;
3326
3344
ctx. stack_size = stack_size;
3345
+ ctx. reg_mapping = reg_mapping;
3327
3346
let blockref = match find_block_version ( blockid, & ctx) {
3328
3347
// If an existing block is found, generate a jump to the block.
3329
3348
Some ( blockref) => {
@@ -3347,8 +3366,8 @@ fn entry_stub_hit_body(
3347
3366
get_or_create_iseq_payload ( iseq) . entries . push ( pending_entry. into_entry ( ) ) ;
3348
3367
}
3349
3368
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) )
3352
3371
}
3353
3372
3354
3373
/// Generate a stub that calls entry_stub_hit
0 commit comments